package apps import ( "context" "gorm.io/datatypes" "gorm.io/gorm" "time" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type AppListLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewAppListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppListLogic { return &AppListLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } type Task struct { Id int64 `db:"id"` // id Name string `db:"name"` // 作业名称 Description string `db:"description"` // 作业描述 Status string `db:"status"` // 作业状态 Strategy int64 `db:"strategy"` // 策略 SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同) CommitTime time.Time `db:"commit_time"` // 提交时间 StartTime string `db:"start_time"` // 开始时间 EndTime string `db:"end_time"` // 结束运行时间 RunningTime int64 `db:"running_time"` // 已运行时间(单位秒) YamlString datatypes.JSON `db:"yaml_string"` Result string `db:"result"` // 作业结果 DeletedAt gorm.DeletedAt `gorm:"index"` NsID string `db:"ns_id"` PName string `db:"p_name"` // p端名称 PId int64 `db:"p_id"` // p端id } func (l *AppListLogic) AppList(req *types.AppListReq) (resp *types.AppListResp, err error) { var tasks []Task resp = &types.AppListResp{} l.svcCtx.DbEngin.Raw("SELECT t.*,phy.name as p_name,phy.id as p_id FROM task t LEFT JOIN cloud c ON c.task_id = t.id join sc_participant_phy_info phy on c.participant_id = phy.id WHERE c.kind in ('Deployment', 'StatefulSet') AND t.`ns_id` = ? AND t.`deleted_at` IS NULL ORDER BY t.created_time Desc", req.NsID).Scan(&tasks) for _, task := range tasks { var replicas []types.Replica l.svcCtx.DbEngin.Raw("SELECT sc_participant_phy_info.name,replica FROM cloud left join sc_participant_phy_info on cloud.participant_id = sc_participant_phy_info.id WHERE task_id =?", task.Id).Scan(&replicas) resp.Apps = append(resp.Apps, types.App{ Id: task.Id, Name: task.Name, Status: task.Status, StartTime: task.StartTime, EndTime: task.EndTime, CreateTime: task.CommitTime.Format("2006-01-02 15:04:05"), ParticipantId: task.PId, ParticipantName: task.PName, Replicas: replicas, }) } return }