作者 tangxvhui

新建

... ... @@ -11,16 +11,15 @@ const (
// 任务
type Task struct {
Id int `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
Name string `json:"name"` // 任务名称
Leader TaskLeader `json:"leader"` // 任务负责人
Status TaskState `json:"status"` // 任务的状态
StageList []TaskStage `json:"stageList"` // 里程碑
Level int `json:"level"` // 优先级,值越小优先级越高
LevalName string `json:"levalName"` // 优先级名称
Id int `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
Name string `json:"name"` // 任务名称
Leader TaskLeader `json:"leader"` // 任务负责人
Status TaskState `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级,值越小优先级越高
LevalName string `json:"levalName"` // 优先级名称
}
type TaskLeader struct {
... ... @@ -49,5 +48,4 @@ type TaskRepository interface {
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*Task, error)
Find(queryOptions map[string]interface{}) (int, []*Task, error)
RemoveStage(stageData TaskStage)
}
... ...
... ... @@ -9,3 +9,10 @@ type TaskIgnore struct {
UserId int `json:"userId"`
CreatedAt time.Time `json:"-"`
}
type TaskIgnoreRepository interface {
Save(param *TaskIgnore) error
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*TaskIgnore, error)
Find(queryOptions map[string]interface{}) (int, []*TaskIgnore, error)
}
... ...
... ... @@ -19,6 +19,12 @@ type TaskStage struct {
Name string `json:"name"` //里程碑名称
SortBy int `json:"sortBy"` //排序
Status TaskStageState `json:"status"` //里程碑完成情况
PlanCompletedAt time.Time `json:"planCompletedAt"` //计划完成时间
RealCompletedAt time.Time `json:"realCompletedAt"` //时间完成时间
PlanCompletedAt int `json:"planCompletedAt"` //计划完成时间
RealCompletedAt int `json:"realCompletedAt"` //时间完成时间
}
type TaskStageRepository interface {
Save(param []*TaskStage) error
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*TaskStage, error)
Find(queryOptions map[string]interface{}) (int, []*TaskStage, error)
}
... ...
... ... @@ -13,6 +13,6 @@ type TaskStage struct {
Name string `pg:"name"` //里程碑名称
SortBy int `pg:"sort_by"` //排序
Status int `pg:"status"` //里程碑完成情况
PlanCompletedAt time.Time `pg:"plan_completed_at"` //计划完成时间
RealCompletedAt time.Time `pg:"real_completed_at"` //时间完成时间
PlanCompletedAt int `pg:"plan_completed_at"` //计划完成时间
RealCompletedAt int `pg:"real_completed_at"` //时间完成时间
}
... ...
package repository
import (
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
//任务
type TaskIgnoreRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.TaskIgnoreRepository = (*TaskIgnoreRepository)(nil)
func (repo *TaskIgnoreRepository) Save(param *domain.TaskIgnore) error {
panic("not implemented") // TODO: Implement
}
func (repo *TaskIgnoreRepository) Remove(id int) error {
panic("not implemented") // TODO: Implement
}
func (repo *TaskIgnoreRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskIgnore, error) {
panic("not implemented") // TODO: Implement
}
func (repo *TaskIgnoreRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskIgnore, error) {
panic("not implemented") // TODO: Implement
}
... ...
package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
//任务
type TaskRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.TaskRepository = (*TaskRepository)(nil)
func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
return &domain.Task{
Id: d.Id,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
Name: d.Name,
Leader: d.Leader,
Status: domain.TaskState(d.Status),
Level: d.Level,
LevalName: d.LevalName,
}
}
func (repo *TaskRepository) Save(param *domain.Task) error {
param.UpdatedAt = time.Now()
if param.Id == 0 {
param.CreatedAt = time.Now()
return nil
}
m := models.Task{
Id: param.Id,
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: param.DeletedAt,
Name: param.Name,
Leader: param.Leader,
Status: int(param.Status),
Level: param.Level,
LevalName: param.LevalName,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
_, err := db.Model(&m).Insert()
if err != nil {
return err
}
} else {
_, err := db.Model(&m).WherePK().Update()
if err != nil {
return err
}
}
param.Id = m.Id
return nil
}
func (repo *TaskRepository) Remove(id int) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.Task{}).
Where("id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
func (repo *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) {
tx := repo.transactionContext.PgTx
m := new(models.Task)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有找到task数据")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return u, nil
}
func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Task, error) {
tx := repo.transactionContext.PgTx
var m []*models.Task
query := tx.Model(&m).
Where("deleted_at isnull").
Limit(20)
query.Order("id desc")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var datas []*domain.Task
for _, v := range m {
d := repo.TransformToDomain(v)
datas = append(datas, d)
}
return count, datas, nil
}
... ...
package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
//任务
type TaskStageRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.TaskStageRepository = (*TaskStageRepository)(nil)
func (repo *TaskStageRepository) TransformToDomain(d *models.TaskStage) *domain.TaskStage {
return &domain.TaskStage{
Id: d.Id,
TaskId: 0,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
Name: d.Name,
SortBy: d.SortBy,
Status: domain.TaskStageState(d.Status),
PlanCompletedAt: d.PlanCompletedAt,
RealCompletedAt: d.RealCompletedAt,
}
}
func (repo *TaskStageRepository) Save(param []*domain.TaskStage) error {
db := repo.transactionContext.PgTx
nowTime := time.Now()
for _, val := range param {
m := models.TaskStage{
Id: val.Id,
TaskId: val.TaskId,
CreatedAt: val.CreatedAt,
UpdatedAt: nowTime,
DeletedAt: val.DeletedAt,
Name: val.Name,
SortBy: val.SortBy,
Status: int(val.Status),
PlanCompletedAt: val.PlanCompletedAt,
RealCompletedAt: val.RealCompletedAt,
}
if m.Id == 0 {
m.CreatedAt = nowTime
_, err := db.Model(&m).Insert()
if err != nil {
return err
}
} else {
_, err := db.Model(&m).WherePK().Update()
if err != nil {
return err
}
}
val.Id = m.Id
}
return nil
}
func (repo *TaskStageRepository) Remove(id int) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.TaskStage{}).
Where("id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
func (repo *TaskStageRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskStage, error) {
tx := repo.transactionContext.PgTx
m := new(models.TaskStage)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有找到task数据")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return u, nil
}
func (repo *TaskStageRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskStage, error) {
tx := repo.transactionContext.PgTx
var m []*models.TaskStage
query := tx.Model(&m).
Where("deleted_at isnull").
Limit(20)
query.Order("id desc")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var datas []*domain.TaskStage
for _, v := range m {
d := repo.TransformToDomain(v)
datas = append(datas, d)
}
return count, datas, nil
}
... ...