瀏覽代碼

新增收款、工时

xuwenhao 8 月之前
父節點
當前提交
37646edb71

+ 8 - 0
server/api/v1/admin/department.go

@@ -135,3 +135,11 @@ func (da *DepartmentApi) FilesUpload(c *gin.Context) {
 	}
 	response.Ok(c)
 }
+
+func (da *DepartmentApi) XiaZai(c *gin.Context) {
+	c.Header("Content-Type", "application/octet-stream")              // 表示是文件流,唤起浏览器下载,一般设置了这个,就要设置文件名
+	c.Header("Content-Disposition", "attachment; filename="+"牛逼.png") // 用来指定下载下来的文件名
+	c.Header("Content-Transfer-Encoding", "binary")                   // 表示传输过程中的编码形式,乱码问题可能就是因为它
+	c.File("uploads/file/04-原理篇.zip")
+	response.Ok(c)
+}

+ 147 - 11
server/api/v1/admin/project.go

@@ -2,8 +2,10 @@ package admin
 
 import (
 	"encoding/json"
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"server/dao"
+	"server/global"
 	"server/model/common/request"
 	"server/model/common/response"
 	"strconv"
@@ -30,7 +32,7 @@ func (pa *ProjectApi) QueryProjectList(c *gin.Context) {
 }
 
 func (pa *ProjectApi) QueryProjectByCode(c *gin.Context) {
-	code := c.Param("code")
+	code := c.Query("code")
 	if code == "" {
 		response.FailWithMessage("编号不能为空", c)
 		return
@@ -43,14 +45,51 @@ func (pa *ProjectApi) QueryProjectByCode(c *gin.Context) {
 	response.OkWithData(project, c)
 }
 
-func (pa *ProjectApi) CreateProject(c *gin.Context) {
-	//var project dao.Project
-	//err := c.ShouldBindJSON(&project)
-	//if err != nil {
-	//	response.FailWithMessage(err.Error(), c)
-	//	return
-	//}
+func (pa *ProjectApi) QueryAllProject(c *gin.Context) {
+	projects, err := projectService.QueryAllProject()
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	response.OkWithData(projects, c)
+}
+
+func (pa *ProjectApi) QueryProjectsInfo(c *gin.Context) {
+	sum, totalProject, completeProject, unCompleteProject, err := projectService.QueryProjectsInfo()
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	response.OkWithData(gin.H{
+		"sum":               sum,
+		"totalProject":      totalProject,
+		"completeProject":   completeProject,
+		"unCompleteProject": unCompleteProject,
+	}, c)
+}
+
+func (pa *ProjectApi) QueryWorkingHours(c *gin.Context) {
+	code := c.Query("code")
+	hours, err := projectService.QueryWorkingHours(code)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	response.OkWithData(hours, c)
+}
+
+func (pa *ProjectApi) QueryCollections(c *gin.Context) {
+	code := c.Query("code")
+	collections, err := projectService.QueryCollections(code)
+	if err != nil {
+		response.FailWithMessage("失败", c)
+		global.GVA_LOG.Error("QueryCollections ====== " + err.Error())
+		return
+	}
+	response.OkWithData(collections, c)
+}
 
+func (pa *ProjectApi) CreateProject(c *gin.Context) {
 	form, err := c.MultipartForm()
 	files := form.File["file"]
 	if err != nil {
@@ -65,9 +104,11 @@ func (pa *ProjectApi) CreateProject(c *gin.Context) {
 		response.FailWithMessage("JSON失败", c)
 		return
 	}
+	fmt.Println(files)
 	for _, file := range files {
 		dst := file.Filename
-
+		fmt.Println(file)
+		fmt.Println(file.Filename)
 		projectFile := dao.ProjectFile{
 			Name: dst,
 			Path: "./uploads/file/" + dst,
@@ -105,6 +146,38 @@ func (pa *ProjectApi) CreateProjectFile(c *gin.Context) {
 	response.OkWithMessage("创建成功", c)
 }
 
+func (pa *ProjectApi) CreateWorkingHours(c *gin.Context) {
+	var working dao.ProjectWorkingHours
+	err := c.ShouldBindJSON(&working)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = projectService.CreateOrUpdateWorkingHours(working)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	response.OkWithMessage("更新成功", c)
+}
+
+func (pa *ProjectApi) CreateCollection(c *gin.Context) {
+	var collection dao.Collection
+	err := c.ShouldBindJSON(&collection)
+	if err != nil {
+		response.FailWithMessage("错误", c)
+		global.GVA_LOG.Error("CreateCollection ====== " + err.Error())
+		return
+	}
+	err = projectService.CreateCollection(collection)
+	if err != nil {
+		response.FailWithMessage("错误", c)
+		global.GVA_LOG.Error("CreateCollection ====== " + err.Error())
+		return
+	}
+	response.OkWithMessage("创建成功", c)
+}
+
 func (pa *ProjectApi) UpdateProject(c *gin.Context) {
 	var project dao.Project
 	err := c.ShouldBindJSON(&project)
@@ -120,8 +193,39 @@ func (pa *ProjectApi) UpdateProject(c *gin.Context) {
 	response.OkWithMessage("更新成功", c)
 }
 
+func (pa *ProjectApi) UpdateWorkingHours(c *gin.Context) {
+	var working dao.ProjectWorkingHours
+	err := c.ShouldBindJSON(&working)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = projectService.UpdateWorkingHours(working)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	response.OkWithMessage("更新成功", c)
+}
+
+func (pa *ProjectApi) UpdateCollection(c *gin.Context) {
+	var collection dao.Collection
+	err := c.ShouldBindJSON(&collection)
+	if err != nil {
+		response.FailWithMessage("错误", c)
+		global.GVA_LOG.Error("UpdateCollection ====== " + err.Error())
+		return
+	}
+	err = projectService.UpdateCollection(collection)
+	if err != nil {
+		response.FailWithMessage("错误", c)
+		global.GVA_LOG.Error("UpdateCollection ====== " + err.Error())
+	}
+	response.OkWithMessage("修改成功", c)
+}
+
 func (pa *ProjectApi) DeleteProject(c *gin.Context) {
-	code := c.Param("code")
+	code := c.Query("code")
 	if code == "" {
 		response.FailWithMessage("编号不能为空", c)
 		return
@@ -135,7 +239,7 @@ func (pa *ProjectApi) DeleteProject(c *gin.Context) {
 }
 
 func (pa *ProjectApi) DeleteProjectFile(c *gin.Context) {
-	id := c.Param("id")
+	id := c.Query("id")
 	i, err := strconv.Atoi(id)
 	if err != nil {
 		response.FailWithMessage(err.Error(), c)
@@ -148,3 +252,35 @@ func (pa *ProjectApi) DeleteProjectFile(c *gin.Context) {
 	}
 	response.OkWithMessage("删除成功", c)
 }
+
+func (pa *ProjectApi) DeleteWorkingHours(c *gin.Context) {
+	var working dao.ProjectWorkingHours
+	err := c.ShouldBindJSON(&working)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = projectService.DeleteWorkingHours(working)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	response.OkWithMessage("删除成功", c)
+}
+
+func (pa *ProjectApi) DeleteCollection(c *gin.Context) {
+	var collection dao.Collection
+	err := c.ShouldBindJSON(&collection)
+	if err != nil {
+		response.FailWithMessage("错误", c)
+		global.GVA_LOG.Error("DeleteCollection ====== " + err.Error())
+		return
+	}
+	err = projectService.DeleteCollection(collection)
+	if err != nil {
+		response.FailWithMessage("错误", c)
+		global.GVA_LOG.Error("DeleteCollection ====== " + err.Error())
+		return
+	}
+	response.OkWithMessage("删除成功", c)
+}

+ 46 - 0
server/dao/collection.go

@@ -0,0 +1,46 @@
+package dao
+
+import (
+	"github.com/shopspring/decimal"
+	"server/global"
+)
+
+type Collection struct {
+	global.GVA_MODEL
+	ProjectCode string          `json:"projectCode" from:"projectCode" gorm:"comment:项目编码"`
+	Price       decimal.Decimal `json:"price" from:"price" gorm:"type:decimal(10,2);not null;comment:收款金额"`
+	Time        string          `json:"time" from:"time" gorm:"comment:收款日期;type:datetime"`
+}
+
+func (Collection) TableName() string {
+	return "collection"
+}
+
+// TODO:收款查询
+
+// QueryCollection 查询收款
+func QueryCollection(code string) (collection []Collection, err error) {
+	err = global.GVA_DB.Model(&Collection{}).Where("project_code = ?", code).Find(&collection).Error
+	return collection, err
+}
+
+// TODO:收款新增
+
+// CreateCollection 新增收款
+func (c Collection) CreateCollection() error {
+	return global.GVA_DB.Create(&c).Error
+}
+
+// TODO:收款修改
+
+// UpdateCollection 修改收款
+func (c Collection) UpdateCollection() error {
+	return global.GVA_DB.Model(&c).Updates(&c).Error
+}
+
+// TODO:收款删除
+
+// DeleteCollection 删除收款
+func (c Collection) DeleteCollection() error {
+	return global.GVA_DB.Unscoped().Delete(&c).Error
+}

+ 14 - 0
server/dao/feeDetails.go

@@ -0,0 +1,14 @@
+package dao
+
+import (
+	"github.com/shopspring/decimal"
+	"server/global"
+)
+
+type FeeDetails struct {
+	global.GVA_MODEL
+	Genre   string          `json:"genre" form:"genre" gorm:"comment:项目类型"`
+	Subject string          `json:"subject" form:"subject" gorm:"comment:科目"`
+	Remarks string          `json:"remarks" form:"remarks" gorm:"comment:备注"`
+	Price   decimal.Decimal `json:"price" form:"price" gorm:"comment:报销金额"`
+}

+ 19 - 10
server/dao/project.go

@@ -8,15 +8,18 @@ import (
 
 type Project struct {
 	global.GVA_MODEL
-	Code       string          `json:"code" form:"code" gorm:"comment:项目编号"`
-	Name       string          `json:"name" form:"name" gorm:"comment:项目名称"`
-	Principal  uint            `json:"principal" form:"principal" gorm:"comment:负责人"`
-	Price      decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(10,2);not null"`
-	Illustrate string          `json:"illustrate" form:"illustrate" gorm:"comment:说明"`
-	Source     string          `json:"source" form:"source" gorm:"comment:来源"`
-	Progress   int             `json:"progress" form:"progress" gorm:"comment:进度"`
-	State      int             `json:"state" form:"state" gorm:"comment:状态"`
-	Files      []ProjectFile   `json:"files" form:"files" gorm:"-"`
+	Code         string                `json:"code" form:"code" gorm:"comment:项目编号"`
+	Name         string                `json:"name" form:"name" gorm:"comment:项目名称"`
+	Principal    string                `json:"principal" form:"principal" gorm:"comment:负责人"`
+	Price        decimal.Decimal       `json:"price" form:"price" gorm:"type:decimal(10,2);not null"`
+	Level        int                   `json:"level" form:"level" gorm:"级别"`
+	Customer     string                `json:"customer" form:"customer" gorm:"相关客户"`
+	Illustrate   string                `json:"illustrate" form:"illustrate" gorm:"comment:说明"`
+	State        int                   `json:"state" form:"state" gorm:"comment:状态"`
+	EndTime      string                `json:"endTime" form:"endTime" gorm:"comment:结束时间"`
+	Files        []ProjectFile         `json:"files" form:"files" gorm:"-"`
+	WorkingHours []ProjectWorkingHours `json:"workingHours" form:"workingHours" gorm:"-"`
+	Collection   []Collection          `json:"collection" form:"collection" gorm:"-"`
 }
 
 func (Project) TableName() string {
@@ -37,7 +40,7 @@ func QueryProjectList(limit, offset, state int, name, time string) (project []*P
 		db = db.Where("name LIKE ?", "%"+name+"%")
 	}
 	if time != "" {
-		db = db.Where("WHERE DATE_FORMAT(created_at, '%Y-%m') = ?", time)
+		db = db.Where("DATE_FORMAT(created_at, '%Y-%m') = ?", time)
 	}
 	err = db.Count(&total).Error
 	if err != nil {
@@ -53,6 +56,12 @@ func QueryProjectByCode(code string) (project Project, err error) {
 	return
 }
 
+// QueryAllProject 查询所以项目
+func QueryAllProject() (projects []Project, err error) {
+	err = global.GVA_DB.Model(&Project{}).Find(&projects).Error
+	return projects, err
+}
+
 // TODO:项目新增
 
 // CreateProject 新增项目

+ 53 - 0
server/dao/projectWorkingHours.go

@@ -0,0 +1,53 @@
+package dao
+
+import (
+	"github.com/shopspring/decimal"
+	"server/global"
+)
+
+type ProjectWorkingHours struct {
+	global.GVA_MODEL
+	ProjectCode string          `json:"projectCode" form:"projectCode" gorm:"comment:项目编号"`
+	People      int             `json:"people" form:"people" gorm:"comment:报工人"`
+	Days        int             `json:"days" form:"days" gorm:"not null;comment:天数"`
+	Price       decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(10,2);not null;comment:人天单价"`
+}
+
+func (ProjectWorkingHours) TableName() string {
+	return "project_working_hours"
+}
+
+// TODO:工时查询
+
+// QueryWorkingHours 查询工时
+func QueryWorkingHours(code string) (workingHours []ProjectWorkingHours, err error) {
+	err = global.GVA_DB.Model(&ProjectWorkingHours{}).Where("project_code = ?", code).Find(&workingHours).Error
+	return workingHours, err
+}
+
+// QueryWorkingHoursByCode 查询单个工时 按id
+func QueryWorkingHoursByCode(code string, people int) (workingHours ProjectWorkingHours, err error) {
+	err = global.GVA_DB.Model(&ProjectWorkingHours{}).Where("code = ? and people = ?", code, people).First(&workingHours).Error
+	return workingHours, err
+}
+
+// TODO:工时新增
+
+// CreateWorkingHours 创建工时
+func (pwh ProjectWorkingHours) CreateWorkingHours() error {
+	return global.GVA_DB.Create(&pwh).Error
+}
+
+// TODO:工时修改
+
+// UpdateWorkingHours 修改工时
+func (pwh ProjectWorkingHours) UpdateWorkingHours() error {
+	return global.GVA_DB.Model(&ProjectWorkingHours{}).Updates(&pwh).Error
+}
+
+// TODO:工时删除
+
+// DeleteWorkingHours 删除工时
+func (pwh ProjectWorkingHours) DeleteWorkingHours() error {
+	return global.GVA_DB.Model(&ProjectWorkingHours{}).Unscoped().Delete(&pwh).Error
+}

+ 51 - 0
server/dao/purchase.go

@@ -0,0 +1,51 @@
+package dao
+
+import (
+	"github.com/shopspring/decimal"
+	"server/global"
+)
+
+type Purchase struct {
+	global.GVA_MODEL
+	ProjectCode string          `json:"projectCode" form:"projectCode" gorm:"comment:项目编码"`
+	Name        string          `json:"name" form:"name" gorm:"comment:名称"`
+	Quantity    int             `json:"quantity" form:"quantity" gorm:"comment:数量"`
+	Company     string          `json:"company" form:"company" gorm:"comment:规格(单位)"`
+	Origin      string          `json:"origin" form:"origin" gorm:"comment:产地"`
+	Price       decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(10,2);not null;"`
+	Amount      decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(10,2);not null;"`
+	Method      string          `json:"method" form:"method" gorm:"comment:付款方式"`
+}
+
+func (Purchase) TableName() string {
+	return "purchase"
+}
+
+// TODO:采购查询
+
+// QueryPurchase 查询采购
+func QueryPurchase(code string) (purchase []Purchase, err error) {
+	err = global.GVA_DB.Model(&Purchase{}).Where("project_code = ?", code).Find(&purchase).Error
+	return purchase, err
+}
+
+// TODO:采购新增
+
+// CreatePurchase 新建采购
+func (p Purchase) CreatePurchase() error {
+	return global.GVA_DB.Create(&p).Error
+}
+
+// TODO:采购修改
+
+// UpdatePurchase 修改采购
+func (p Purchase) UpdatePurchase() error {
+	return global.GVA_DB.Model(&p).Updates(&p).Error
+}
+
+// TODO:采购删除
+
+// DeletePurchase 删除采购
+func (p Purchase) DeletePurchase() error {
+	return global.GVA_DB.Unscoped().Delete(&p).Error
+}

+ 54 - 0
server/dao/reimbursement.go

@@ -0,0 +1,54 @@
+package dao
+
+import (
+	"github.com/shopspring/decimal"
+	"server/global"
+)
+
+type Reimbursement struct {
+	global.GVA_MODEL
+	ProjectCode string          `json:"projectCode" form:"projectCode" gorm:"comment:项目编号"`
+	Name        string          `json:"name" form:"name" gorm:"comment:项目名称"`
+	Applicant   string          `json:"applicant" form:"applicant" gorm:"comment:报销申请人"`
+	Approval    string          `json:"approval" form:"approval" gorm:"comment:报销审批人"`
+	Price       decimal.Decimal `json:"price" form:"price" gorm:"comment:项目金额"`
+	Genre       string          `json:"genre" form:"genre" gorm:"comment:项目类型"`
+	FeeDetails  []FeeDetails    `json:"feeDetails" form:"feeDetails" gorm:"-"`
+}
+
+func (Reimbursement) TableName() string {
+	return "reimbursement"
+}
+
+// TODO:报销查询
+
+// QueryReimbursementList 查询报销
+func QueryReimbursementList() {
+
+}
+
+func QueryReimbursement(code string) (reimbursement []Reimbursement, err error) {
+	err = global.GVA_DB.Model(&Reimbursement{}).Where("project_code = ?", code).Find(&reimbursement).Error
+	return reimbursement, err
+}
+
+// TODO:报销新增
+
+// CreateReimbursement 新增报销单
+func (r Reimbursement) CreateReimbursement() error {
+	return global.GVA_DB.Create(&r).Error
+}
+
+// TODO:报销修改
+
+// UpdateReimbursement 修改报销单
+func (r Reimbursement) UpdateReimbursement() error {
+	return global.GVA_DB.Model(&r).Updates(&r).Error
+}
+
+// TODO:报销删除
+
+// DeleteReimbursement 删除报销单
+func (r Reimbursement) DeleteReimbursement() error {
+	return global.GVA_DB.Unscoped().Delete(&r).Error
+}

+ 2 - 0
server/initialize/gorm.go

@@ -49,6 +49,8 @@ func RegisterTables() {
 		dao.Department{},
 		dao.Project{},
 		dao.ProjectFile{},
+		dao.ProjectWorkingHours{},
+		dao.Collection{},
 	)
 	if err != nil {
 		global.GVA_LOG.Error("register table failed", zap.Error(err))

+ 1 - 1
server/initialize/router.go

@@ -88,7 +88,7 @@ func Routers() *gin.Engine {
 		exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup)
 
 		adminRouter.InitDepartmentRouter(PublicGroup)
-		adminRouter.InitProjectRouter(PublicGroup)
+		adminRouter.InitProjectRouter(PrivateGroup)
 	}
 
 	global.GVA_LOG.Info("router register success")

+ 1 - 0
server/router/admin/department.go

@@ -24,5 +24,6 @@ func (s *DepartmentRouter) InitDepartmentRouter(Router *gin.RouterGroup) {
 		departmentRouterWithoutRecord.GET("queryAllDep", departmentApi.QueryAllDep)
 		departmentRouterWithoutRecord.GET("queryDepByStart", departmentApi.QueryDepByStart)
 		departmentRouterWithoutRecord.POST("filesUpload", departmentApi.FilesUpload)
+		departmentRouterWithoutRecord.GET("xiazai", departmentApi.XiaZai)
 	}
 }

+ 15 - 3
server/router/admin/project.go

@@ -15,12 +15,24 @@ func (s *ProjectRouter) InitProjectRouter(Router *gin.RouterGroup) {
 	{
 		projectRouter.POST("createProject", projectApi.CreateProject)
 		projectRouter.POST("createProjectFile", projectApi.CreateProjectFile)
+		projectRouter.POST("createWorkingHours", projectApi.CreateWorkingHours)
+		projectRouter.POST("createCollection", projectApi.CreateCollection)
+
 		projectRouter.PUT("updateProject", projectApi.UpdateProject)
-		projectRouter.DELETE("deleteProject/:code", projectApi.DeleteProject)
-		projectRouter.DELETE("deleteProjectFile/:id", projectApi.DeleteProjectFile)
+		projectRouter.PUT("updateWorkingHours", projectApi.UpdateWorkingHours)
+		projectRouter.PUT("updateCollection", projectApi.UpdateCollection)
+
+		projectRouter.DELETE("deleteProject", projectApi.DeleteProject)
+		projectRouter.DELETE("deleteProjectFile", projectApi.DeleteProjectFile)
+		projectRouter.DELETE("deleteWorkingHours", projectApi.DeleteWorkingHours)
+		projectRouter.DELETE("deleteCollection", projectApi.DeleteCollection)
 	}
 	{
 		projectRouterWithoutRecord.POST("queryProjectList", projectApi.QueryProjectList)
-		projectRouterWithoutRecord.GET("queryProjectByCode/:code", projectApi.QueryProjectByCode)
+		projectRouterWithoutRecord.GET("queryProjectByCode", projectApi.QueryProjectByCode)
+		projectRouterWithoutRecord.GET("queryAllProject", projectApi.QueryAllProject)
+		projectRouterWithoutRecord.GET("queryProjectsInfo", projectApi.QueryProjectsInfo)
+		projectRouterWithoutRecord.GET("queryWorkingHours", projectApi.QueryWorkingHours)
+		projectRouterWithoutRecord.GET("queryCollection", projectApi.QueryCollections)
 	}
 }

+ 71 - 1
server/service/admin/project.go

@@ -1,6 +1,8 @@
 package admin
 
 import (
+	"fmt"
+	"github.com/shopspring/decimal"
 	"server/dao"
 	"server/model/common/request"
 )
@@ -10,7 +12,6 @@ type ProjectService struct{}
 func (ps *ProjectService) QueryProjectList(info request.SearchProject) (list interface{}, total int64, err error) {
 	limit := info.PageInfo.PageSize
 	offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
-
 	project, total, err := dao.QueryProjectList(limit, offset, info.State, info.Name, info.Time)
 	return project, total, err
 }
@@ -28,6 +29,36 @@ func (ps *ProjectService) QueryProjectByCode(code string) (project dao.Project,
 	return project, err
 }
 
+func (ps *ProjectService) QueryAllProject() ([]dao.Project, error) {
+	return dao.QueryAllProject()
+}
+
+func (ps *ProjectService) QueryProjectsInfo() (sum decimal.Decimal, totalProject, completeProject, unCompleteProject int, err error) {
+
+	projects, err := dao.QueryAllProject()
+	if err != nil {
+		return
+	}
+	for _, project := range projects {
+		totalProject++
+		if project.State == 3 {
+			completeProject++
+		}
+		sum = sum.Add(project.Price)
+	}
+	fmt.Printf("%y", sum)
+	unCompleteProject = totalProject - completeProject
+	return
+}
+
+func (ps *ProjectService) QueryWorkingHours(code string) ([]dao.ProjectWorkingHours, error) {
+	return dao.QueryWorkingHours(code)
+}
+
+func (ps *ProjectService) QueryCollections(code string) ([]dao.Collection, error) {
+	return dao.QueryCollection(code)
+}
+
 func (ps *ProjectService) CreateProject(project dao.Project) error {
 	return project.CreateProject()
 }
@@ -36,10 +67,41 @@ func (ps *ProjectService) CreateProjectFile(projectFile dao.ProjectFile) error {
 	return projectFile.CreateFile()
 }
 
+func (ps *ProjectService) CreateOrUpdateWorkingHours(workingHours dao.ProjectWorkingHours) error {
+	// 查询是否已有工时
+	hours, err := dao.QueryWorkingHoursByCode(workingHours.ProjectCode, workingHours.People)
+	if err != nil { // 创建时没有id 判断是创建还是修改
+		// 新增工时+已有工时
+		zongHours := hours.Days + workingHours.Days
+		workingHours.Days = zongHours
+
+		err = workingHours.UpdateWorkingHours()
+		return err
+	} else {
+		err := workingHours.CreateWorkingHours()
+		if err != nil {
+			return err
+		}
+		return err
+	}
+}
+
+func (ps *ProjectService) CreateCollection(collection dao.Collection) error {
+	return collection.CreateCollection()
+}
+
 func (ps *ProjectService) UpdateProject(project dao.Project) error {
 	return project.UpdateProject()
 }
 
+func (ps *ProjectService) UpdateWorkingHours(workingHours dao.ProjectWorkingHours) error {
+	return workingHours.UpdateWorkingHours()
+}
+
+func (ps *ProjectService) UpdateCollection(collection dao.Collection) error {
+	return collection.UpdateCollection()
+}
+
 func (ps *ProjectService) DeleteProject(code string) error {
 	return dao.DeleteProject(code)
 }
@@ -47,3 +109,11 @@ func (ps *ProjectService) DeleteProject(code string) error {
 func (ps *ProjectService) DeleteProjectFile(id uint) error {
 	return dao.DeleteFile(id)
 }
+
+func (ps *ProjectService) DeleteWorkingHours(workingHours dao.ProjectWorkingHours) error {
+	return workingHours.DeleteWorkingHours()
+}
+
+func (ps *ProjectService) DeleteCollection(collection dao.Collection) error {
+	return collection.DeleteCollection()
+}

+ 8 - 1
web/src/api/department.js

@@ -59,4 +59,11 @@ export const fileUpload = (data) => {
     method: 'post',
     data
   })
-}
+}
+
+export const xia = () => {
+  return service({
+    url: '/department/xiazai',
+    method: 'get'
+  })
+}

+ 33 - 1
web/src/view/department/department.vue

@@ -150,6 +150,8 @@
           </template>
         </el-upload>
         <el-button @click="submitUpload">上传</el-button>
+        <a href="http://localhost:8080/api/department/xiazai">下载</a>
+        <el-button @click="xiazai">下载</el-button>
       </div>
     </el-main>
     <!--    新增-->
@@ -296,12 +298,14 @@ import {
   updateDep,
   updateDepStatus,
   updateUserDep,
-  fileUpload
+  fileUpload,
+  xia
 } from '@/api/department'
 import CustomPic from '@/components/customPic/index.vue'
 import WarningBar from '@/components/warningBar/warningBar.vue'
 import { getAllUsers } from '@/api/user'
 import { ElMessage, ElMessageBox } from 'element-plus'
+import axios from 'axios'
 
 const files = ref()
 
@@ -339,6 +343,34 @@ const submitUpload = async() => {
   })
 }
 
+// 下载
+const xiazai = async() => {
+  try {
+    const response = await axios({
+      method: 'get',
+      url: 'http://localhost:8080/api/department/xiazai?api_key=' + Math.floor(Math.random() * 1000000),
+      responseType: 'blob'
+    })
+
+    const blob = new Blob([response.data], {
+      type: 'application/png' // 根据实际文件类型调整
+    })
+
+    const downloadUrl = window.URL.createObjectURL(blob)
+
+    const link = document.createElement('a')
+    link.href = downloadUrl
+    // link.download = response.headers[fileNameHeader] || 'default-filename.png' // 如果没有提供文件名,使用默认名
+    link.download = '04-原理篇.zip'
+    document.body.appendChild(link)
+    link.click()
+    document.body.removeChild(link)
+    window.URL.revokeObjectURL(downloadUrl)
+  } catch (error) {
+    console.error('Download failed:', error)
+  }
+}
+
 const depTableData = ref([])
 
 const queryData = async() => {