增加任务管理模块
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// Task 任务模型(对应表 yz_tenant_tasks)
|
||||
type Task struct {
|
||||
Id int `orm:"auto" json:"id"`
|
||||
TenantId int `orm:"column(tenant_id)" json:"tenant_id"`
|
||||
TaskNo string `orm:"column(task_no);size(64)" json:"task_no"`
|
||||
TaskName string `orm:"column(task_name);size(255)" json:"task_name"`
|
||||
TaskDesc string `orm:"column(task_desc);type(text);null" json:"task_desc"`
|
||||
TaskType string `orm:"column(task_type);size(32);null" json:"task_type"`
|
||||
BusinessTag string `orm:"column(business_tag);size(64);null" json:"business_tag"`
|
||||
ParentTaskId int `orm:"column(parent_task_id);null" json:"parent_task_id"`
|
||||
ProjectId int `orm:"column(project_id);null" json:"project_id"`
|
||||
RelatedId int `orm:"column(related_id);null" json:"related_id"`
|
||||
RelatedType string `orm:"column(related_type);size(32);null" json:"related_type"`
|
||||
TeamEmployeeIds string `orm:"column(team_employee_ids);size(512);null" json:"team_employee_ids"`
|
||||
CreatorId int `orm:"column(creator_id)" json:"creator_id"`
|
||||
CreatorName string `orm:"column(creator_name);size(64)" json:"creator_name"`
|
||||
PrincipalId int `orm:"column(principal_id)" json:"principal_id"`
|
||||
PrincipalName string `orm:"column(principal_name);size(64)" json:"principal_name"`
|
||||
ParticipantIds string `orm:"column(participant_ids);size(512);null" json:"participant_ids"`
|
||||
ParticipantNames string `orm:"column(participant_names);size(512);null" json:"participant_names"`
|
||||
CcIds string `orm:"column(cc_ids);size(512);null" json:"cc_ids"`
|
||||
CcNames string `orm:"column(cc_names);size(512);null" json:"cc_names"`
|
||||
PlanStartTime *time.Time `orm:"column(plan_start_time);null;type(datetime)" json:"plan_start_time"`
|
||||
PlanEndTime time.Time `orm:"column(plan_end_time);type(datetime)" json:"plan_end_time"`
|
||||
ActualStartTime *time.Time `orm:"column(actual_start_time);null;type(datetime)" json:"actual_start_time"`
|
||||
ActualEndTime *time.Time `orm:"column(actual_end_time);null;type(datetime)" json:"actual_end_time"`
|
||||
EstimatedHours float64 `orm:"column(estimated_hours);null;digits(10);decimals(2)" json:"estimated_hours"`
|
||||
ActualHours float64 `orm:"column(actual_hours);null;digits(10);decimals(2)" json:"actual_hours"`
|
||||
TaskStatus string `orm:"column(task_status);size(32)" json:"task_status"`
|
||||
Priority string `orm:"column(priority);size(16)" json:"priority"`
|
||||
Progress int8 `orm:"column(progress)" json:"progress"`
|
||||
NeedApproval int8 `orm:"column(need_approval)" json:"need_approval"`
|
||||
ApprovalId int `orm:"column(approval_id);null" json:"approval_id"`
|
||||
DelayApproved int8 `orm:"column(delay_approved)" json:"delay_approved"`
|
||||
OldPlanEndTime *time.Time `orm:"column(old_plan_end_time);null;type(datetime)" json:"old_plan_end_time"`
|
||||
RepeatType string `orm:"column(repeat_type);size(16);null" json:"repeat_type"`
|
||||
RepeatCycle int `orm:"column(repeat_cycle);null" json:"repeat_cycle"`
|
||||
RepeatEndTime *time.Time `orm:"column(repeat_end_time);null;type(datetime)" json:"repeat_end_time"`
|
||||
AttachmentIds string `orm:"column(attachment_ids);size(1024);null" json:"attachment_ids"`
|
||||
Remark string `orm:"column(remark);size(512);null" json:"remark"`
|
||||
IsArchived int8 `orm:"column(is_archived)" json:"is_archived"`
|
||||
ArchiveTime *time.Time `orm:"column(archive_time);null;type(datetime)" json:"archive_time"`
|
||||
CreatedTime time.Time `orm:"column(created_time);type(datetime);auto_now_add" json:"created_time"`
|
||||
UpdatedTime time.Time `orm:"column(updated_time);type(datetime);auto_now" json:"updated_time"`
|
||||
DeletedTime *time.Time `orm:"column(deleted_time);null;type(datetime)" json:"deleted_time"`
|
||||
OperatorId int `orm:"column(operator_id);null" json:"operator_id"`
|
||||
OperatorName string `orm:"column(operator_name);size(64);null" json:"operator_name"`
|
||||
}
|
||||
|
||||
func (t *Task) TableName() string {
|
||||
return "yz_tenant_tasks"
|
||||
}
|
||||
|
||||
func init() {
|
||||
orm.RegisterModel(new(Task))
|
||||
}
|
||||
|
||||
// -------- 数据访问函数 ---------
|
||||
|
||||
// ListTasks 分页查询任务
|
||||
func ListTasks(tenantId int, keyword, status, priority string, page, pageSize int) (tasks []*Task, total int64, err error) {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(new(Task)).Filter("tenant_id", tenantId).Filter("deleted_time__isnull", true)
|
||||
|
||||
if keyword != "" {
|
||||
cond := orm.NewCondition()
|
||||
cond1 := cond.Or("task_name__icontains", keyword).Or("task_no__icontains", keyword).Or("principal_name__icontains", keyword)
|
||||
qs = qs.SetCond(cond1)
|
||||
}
|
||||
if status != "" {
|
||||
qs = qs.Filter("task_status", status)
|
||||
}
|
||||
if priority != "" {
|
||||
qs = qs.Filter("priority", priority)
|
||||
}
|
||||
|
||||
total, err = qs.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
_, err = qs.OrderBy("-id").Limit(pageSize, offset).All(&tasks)
|
||||
return
|
||||
}
|
||||
|
||||
// GetTaskById 获取单个任务
|
||||
func GetTaskById(id int) (*Task, error) {
|
||||
o := orm.NewOrm()
|
||||
t := Task{Id: id}
|
||||
err := o.Read(&t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
// CreateTask 新建任务
|
||||
func CreateTask(t *Task) error {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(t)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateTask 更新任务
|
||||
func UpdateTask(t *Task, cols ...string) error {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(t, cols...)
|
||||
return err
|
||||
}
|
||||
@@ -29,6 +29,17 @@ type User struct {
|
||||
LastLoginIp string `orm:"column(last_login_ip);null;size(50)" json:"last_login_ip"`
|
||||
}
|
||||
|
||||
// GetUserById 根据ID获取用户信息
|
||||
func GetUserById(id int) (*User, error) {
|
||||
o := orm.NewOrm()
|
||||
user := &User{Id: id}
|
||||
err := o.Read(user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
// TableName 设置表名,默认为yz_users
|
||||
func (u *User) TableName() string {
|
||||
return "yz_users"
|
||||
@@ -47,6 +58,7 @@ func Init(version string) {
|
||||
orm.RegisterModel(new(DictType))
|
||||
orm.RegisterModel(new(DictItem))
|
||||
orm.RegisterModel(new(OperationLog))
|
||||
orm.RegisterModel(new(AccessLog))
|
||||
|
||||
ormConfig, err := beego.AppConfig.String("orm")
|
||||
if err != nil {
|
||||
@@ -90,5 +102,20 @@ func Init(version string) {
|
||||
fmt.Println("数据库连接成功!")
|
||||
fmt.Printf("当前项目版本: %s\n", version)
|
||||
fmt.Println("数据库连接池配置: MaxIdleConns=10, MaxOpenConns=100, ConnMaxLifetime=1h")
|
||||
|
||||
// 自动创建或更新表结构
|
||||
o := orm.NewOrm()
|
||||
_, err = o.Raw("SET FOREIGN_KEY_CHECKS=0").Exec()
|
||||
if err != nil {
|
||||
fmt.Println("关闭外键检查失败:", err)
|
||||
}
|
||||
if err := orm.RunSyncdb("default", false, true); err != nil {
|
||||
fmt.Println("数据库表同步失败:", err)
|
||||
}
|
||||
_, err = o.Raw("SET FOREIGN_KEY_CHECKS=1").Exec()
|
||||
if err != nil {
|
||||
fmt.Println("启用外键检查失败:", err)
|
||||
}
|
||||
fmt.Println("数据库表自动同步完成")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user