73 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package project
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"strconv"
 | |
| 
 | |
| 	db "management/internal/db/sqlc"
 | |
| 	"management/internal/global"
 | |
| )
 | |
| 
 | |
| func CreateProject(ctx context.Context, p *db.CreateProjectParams, pf []*db.CreateProjectFileParams) error {
 | |
| 	return db.Engine.ExecTx(ctx, func(q *db.Queries) error {
 | |
| 		_, err := q.CreateProject(ctx, p)
 | |
| 		if err != nil {
 | |
| 			return err
 | |
| 		}
 | |
| 
 | |
| 		for _, item := range pf {
 | |
| 			_, err = q.CreateProjectFile(ctx, item)
 | |
| 			if err != nil {
 | |
| 				return err
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		return nil
 | |
| 	})
 | |
| }
 | |
| 
 | |
| func UpdateProject(ctx context.Context, p *db.UpdateProjectParams, pf []*db.CreateProjectFileParams) error {
 | |
| 	return db.Engine.ExecTx(ctx, func(q *db.Queries) error {
 | |
| 		_, err := q.UpdateProject(ctx, p)
 | |
| 		if err != nil {
 | |
| 			return err
 | |
| 		}
 | |
| 
 | |
| 		err = q.DeleteProjectFile(ctx, p.ID)
 | |
| 		if err != nil {
 | |
| 			return err
 | |
| 		}
 | |
| 
 | |
| 		for _, item := range pf {
 | |
| 			_, err = q.CreateProjectFile(ctx, item)
 | |
| 			if err != nil {
 | |
| 				return err
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		return nil
 | |
| 	})
 | |
| }
 | |
| 
 | |
| func AllProjects(ctx context.Context) []*global.DataDict {
 | |
| 	pp, err := db.Engine.AllProjects(ctx)
 | |
| 	if err != nil || len(pp) == 0 {
 | |
| 		return nil
 | |
| 	}
 | |
| 
 | |
| 	var res []*global.DataDict
 | |
| 	res = append(res, &global.DataDict{
 | |
| 		Name:  "请选择",
 | |
| 		Value: "0",
 | |
| 	})
 | |
| 	for _, v := range pp {
 | |
| 		item := global.DataDict{
 | |
| 			Name:  v.Name,
 | |
| 			Value: strconv.Itoa(int(v.ID)),
 | |
| 		}
 | |
| 		res = append(res, &item)
 | |
| 	}
 | |
| 
 | |
| 	return res
 | |
| }
 |