first commit

This commit is contained in:
2025-03-21 11:05:42 +08:00
commit 7dffc94035
1717 changed files with 724764 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
package form
import (
"time"
db "management/internal/db/sqlc"
"management/internal/pkg/convertor"
"github.com/jackc/pgx/v5/pgtype"
)
type BudgetForm struct {
ID int64 `json:"id"`
ProjectID int64 `json:"project_id"`
Name string `json:"name"`
BudgetType int32 `json:"budget_type"`
Category int32 `json:"category"`
StartAt time.Time `json:"start_at"`
EndAt time.Time `json:"end_at"`
Amount float64 `json:"amount"`
AmountF pgtype.Numeric `comment:"预算金额"`
UsedAmount float64 `json:"used_amount"`
UsedAmountF pgtype.Numeric `comment:"已支付金额"`
RemainingAmount float64 `json:"remaining_amount"`
RemainingAmountF pgtype.Numeric `comment:"剩余金额"`
Remark string `json:"remark"`
Status int16 `json:"status"`
Sort int32 `json:"sort"`
CreatedAt time.Time `json:"created_at"`
CreatedName string `comment:"创建人"`
UpdatedAt time.Time `json:"updated_at"`
UpdatedName string `comment:"更新人"`
}
func (f *BudgetForm) ToForm(p *db.Budget) *BudgetForm {
return &BudgetForm{
ID: p.ID,
ProjectID: p.ProjectID,
Name: p.Name,
BudgetType: p.BudgetType,
Category: p.Category,
StartAt: p.StartAt,
EndAt: p.EndAt,
Amount: convertor.NumericToFloat64(p.Amount),
UsedAmount: convertor.NumericToFloat64(p.UsedAmount),
RemainingAmount: convertor.NumericToFloat64(p.RemainingAmount),
Remark: p.Remark,
Status: p.Status,
Sort: p.Sort,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
}
}

View File

@@ -0,0 +1,39 @@
package form
import (
"time"
db "management/internal/db/sqlc"
)
type CustomerForm struct {
ID int64 `json:"id" validate:"min=0" comment:"ID"`
Name string `json:"name" validate:"required" comment:"名称"`
Category int32 `json:"category" validate:"min=0" comment:"类别"`
Source int32 `json:"source" validate:"min=0" comment:"来源"`
Address string `json:"address" comment:"地址"`
ContactName string `json:"contact_name" comment:"联系人姓名"`
ContactPhone string `json:"contact_phone" validate:"telephone" comment:"联系人手机"`
Status int16 `json:"status" validate:"min=-1" comment:"状态"`
Sort int32 `json:"sort" validate:"min=0" comment:"排序"`
CreatedAt time.Time `json:"created_at" comment:"创建时间"`
CreatedBy string `json:"created_by" comment:"创建人"`
UpdatedAt time.Time `json:"updated_at" comment:"更新时间"`
UpdatedBy string `json:"updated_by" comment:"更新人"`
}
func (f *CustomerForm) ToForm(c *db.Customer) *CustomerForm {
return &CustomerForm{
ID: c.ID,
Name: c.Name,
Category: c.Category,
Source: c.Source,
Address: c.Address,
ContactName: c.ContactName,
ContactPhone: c.ContactPhone,
Status: c.Status,
Sort: c.Sort,
CreatedAt: c.CreatedAt,
UpdatedAt: c.UpdatedAt,
}
}

View File

@@ -0,0 +1,42 @@
package form
import (
"time"
db "management/internal/db/sqlc"
"management/internal/pkg/convertor"
"github.com/jackc/pgx/v5/pgtype"
)
type ExpenseForm struct {
ID int64 `json:"id"`
ProjectID int64 `json:"project_id"`
BudgetID int64 `json:"budget_id"`
Amount float64 `json:"amount"`
AmountF pgtype.Numeric `comment:"报销金额"`
ExpensesAt time.Time `json:"expenses_at"`
ExpensesType int32 `json:"expenses_type"`
Remark string `json:"remark"`
Status int16 `json:"status"`
CreatedAt time.Time `json:"created_at"`
CreatedName string `comment:"创建人"`
UpdatedAt time.Time `json:"updated_at"`
UpdatedName string `comment:"更新人"`
}
func (f *ExpenseForm) ToForm(p *db.Expense) *ExpenseForm {
return &ExpenseForm{
ID: p.ID,
ProjectID: p.ProjectID,
BudgetID: p.BudgetID,
Amount: convertor.NumericToFloat64(p.Amount),
AmountF: p.Amount,
ExpensesAt: p.ExpensesAt,
ExpensesType: p.ExpensesType,
Remark: p.Remark,
Status: p.Status,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
}
}

View File

@@ -0,0 +1,40 @@
package form
import (
"net/http"
"management/internal/pkg/validation"
"github.com/gorilla/schema"
)
// 初始化一个解码器实例
var decoder = schema.NewDecoder()
func BindForm(r *http.Request, form any) error {
if err := r.ParseForm(); err != nil {
return err
}
// 忽略名为 "csrf_token" 的表单字段
delete(r.PostForm, "csrf_token")
// decoder.RegisterConverter(time.Time{}, func(s string) reflect.Value {
// res, err := time.ParseInLocation("2006-01-02", s, time.Local)
// if err != nil {
// panic(err)
// }
// return reflect.ValueOf(res)
// })
if err := decoder.Decode(form, r.PostForm); err != nil {
return err
}
// 校验表单规则
if err := validation.ValidateForm(form); err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,44 @@
package form
import (
"time"
db "management/internal/db/sqlc"
"management/internal/pkg/convertor"
"github.com/jackc/pgx/v5/pgtype"
)
type IncomeForm struct {
ID int64 `json:"id"`
ProjectID int64 `json:"project_id"`
BudgetID int64 `json:"budget_id"`
Amount float64 `json:"amount"`
AmountF pgtype.Numeric `comment:"收入金额"`
IncomeAt time.Time `json:"income_at"`
IncomeType int32 `json:"income_type"`
IncomeBank int32 `json:"income_bank"`
Remark string `json:"remark"`
Status int16 `json:"status"`
CreatedAt time.Time `json:"created_at"`
CreatedName string `comment:"创建人"`
UpdatedAt time.Time `json:"updated_at"`
UpdatedName string `comment:"更新人"`
}
func (f *IncomeForm) ToForm(p *db.Income) *IncomeForm {
return &IncomeForm{
ID: p.ID,
ProjectID: p.ProjectID,
BudgetID: p.BudgetID,
Amount: convertor.NumericToFloat64(p.Amount),
AmountF: p.Amount,
IncomeAt: p.IncomeAt,
IncomeType: p.IncomeType,
IncomeBank: p.IncomeBank,
Remark: p.Remark,
Status: p.Status,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
}
}

View File

@@ -0,0 +1,80 @@
package form
import (
"time"
db "management/internal/db/sqlc"
"management/internal/pkg/convertor"
"github.com/jackc/pgx/v5/pgtype"
)
type ProjectFileForm struct {
Combination string `schema:"-"`
ProjectFileItems []*ProjectFileItemForm `schema:"-"`
}
type ProjectFileItemForm struct {
Name string `schema:"-"`
Path string `schema:"-"`
Combination string `schema:"-"`
}
type ProjectForm struct {
ID int64 `validate:"min=0" comment:"ID"`
Name string `validate:"required" comment:"名称"`
StartAt time.Time `validate:"required" comment:"开始时间"`
EndAt time.Time `validate:"required" comment:"结束时间"`
CustomerID int64 `validate:"required" comment:"客户ID"`
CustomerName string `comment:"客户名称"`
TotalMoney float64 `validate:"required" comment:"总金额"`
TotalMoneyF pgtype.Numeric `comment:"总金额"`
Description string `comment:"简介"`
ApplyAt time.Time `validate:"required" comment:"申请时间"`
ApplyUserID int32 `validate:"required" comment:"申请人"`
ApplyUserName string `comment:"申请人"`
ManagerID int32 `comment:"项目经理"`
ManagerName string `comment:"项目经理"`
Members string `comment:"项目成员"`
MembersName string `comment:"项目成员"`
Status int16 `validate:"min=-1" comment:"状态"`
Sort int32 `validate:"min=0" comment:"排序"`
CreatedAt time.Time `comment:"创建时间"`
CreatedName string `comment:"创建人"`
UpdatedAt time.Time `comment:"更新时间"`
UpdatedName string `comment:"更新人"`
ProjectFiles *ProjectFileForm `schema:"-"`
}
func (f *ProjectForm) ToForm(p *db.Project, pfs []*db.ProjectFile) *ProjectForm {
var allCombinationPath string
var pfi []*ProjectFileItemForm
for _, pf := range pfs {
pfi = append(pfi, &ProjectFileItemForm{
Name: pf.Name,
Path: pf.Path,
Combination: pf.Name + "|" + pf.Path,
})
allCombinationPath += pf.Name + "|" + pf.Path + ","
}
return &ProjectForm{
ID: p.ID,
Name: p.Name,
StartAt: p.StartAt,
EndAt: p.EndAt,
CustomerID: p.CustomerID,
TotalMoney: convertor.NumericToFloat64(p.TotalMoney),
Description: p.Description,
ApplyAt: p.ApplyAt,
ApplyUserID: p.ApplyUserID,
ManagerID: p.ManagerID,
Members: p.Members,
Status: p.Status,
Sort: p.Sort,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
ProjectFiles: &ProjectFileForm{
Combination: allCombinationPath,
ProjectFileItems: pfi,
},
}
}