123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- package admin
- import (
- "fmt"
- "github.com/shopspring/decimal"
- "server/dao"
- "server/model/common/request"
- "time"
- )
- 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)
- for i, p := range project {
- collection, err := dao.QueryCollection(p.Code)
- if err != nil {
- return nil, total, err
- }
- project[i].Collection = collection
- }
- return project, total, err
- }
- func (ps *ProjectService) QueryProjectByCode(code string) (project dao.Project, err error) {
- project, err = dao.QueryProjectByCode(code)
- if err != nil {
- return
- }
- files, err := dao.QueryFilesByCode(code)
- if err != nil {
- return
- }
- project.Files = files
- return project, err
- }
- func (ps *ProjectService) QueryFileList(info request.SearchProjectFileList) (list interface{}, total int64, err error) {
- limit := info.PageInfo.PageSize
- offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
- files, total, err := dao.QueryFileList(limit, offset, info.Genre, info.Code, info.Name)
- return files, total, err
- }
- func (ps *ProjectService) QueryFilesByNameOrGenre(info request.SearchProjectFileList) ([]dao.ProjectFile, error) {
- return dao.QueryFilesByNameOrGenre(info.Genre, info.Code, info.Name)
- }
- 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) QueryProjectState() ([]dao.ProjectState, error) {
- return dao.QueryProjectState()
- }
- 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) QueryReimbursementList(info request.SearchProjectList) (list interface{}, total int64, err error) {
- limit := info.PageInfo.PageSize
- offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
- return dao.QueryReimbursementList(limit, offset, info.Code, info.Name)
- }
- func (ps *ProjectService) QueryReimbursement(code string) ([]dao.Reimbursement, error) {
- reimbursements, err := dao.QueryReimbursement(code)
- if err != nil {
- return nil, err
- }
- for i, reimbursement := range reimbursements {
- details, err := dao.QueryFeeDetails(int(reimbursement.ID))
- if err != nil {
- return nil, err
- }
- reimbursements[i].FeeDetails = details
- }
- return reimbursements, err
- }
- func (ps *ProjectService) CreateProject(project dao.Project) error {
- return project.CreateProject()
- }
- func (ps *ProjectService) CreateProjectFile(projectFile dao.ProjectFile) error {
- return projectFile.CreateFile()
- }
- func (ps *ProjectService) CreateProjectState(projectState dao.ProjectState) error {
- return projectState.CreateProjectState()
- }
- 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
- workingHours.Price = hours.Price
- 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) CreateReimbursement(reimbursement dao.Reimbursement) error {
- return reimbursement.CreateReimbursement()
- }
- func (ps *ProjectService) UpdateProject(project dao.Project) error {
- if project.State == 3 {
- project.CollectionTime = time.Now().Format("2006-01-02 15:04:05")
- } else if project.State == 4 || project.State == 5 {
- project.EndTime = time.Now().Format("2006-01-02 15:04:05")
- }
- return project.UpdateProject()
- }
- func (ps *ProjectService) UpdateProjectState(projectState dao.ProjectState) error {
- return projectState.UpdateProjectState()
- }
- 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) UpdateReimbursement(reimbursement dao.Reimbursement) error {
- return reimbursement.UpdateReimbursement()
- }
- func (ps *ProjectService) DeleteProject(code string) error {
- return dao.DeleteProject(code)
- }
- func (ps *ProjectService) DeleteProjectFile(id uint) error {
- return dao.DeleteFile(id)
- }
- func (ps *ProjectService) DeleteProjectState(projectState dao.ProjectState) error {
- return projectState.DeleteProjectState()
- }
- func (ps *ProjectService) DeleteWorkingHours(workingHours dao.ProjectWorkingHours) error {
- return workingHours.DeleteWorkingHours()
- }
- func (ps *ProjectService) DeleteCollection(collection dao.Collection) error {
- return collection.DeleteCollection()
- }
- func (ps *ProjectService) DeleteReimbursement(reimbursement dao.Reimbursement) error {
- return reimbursement.DeleteReimbursement()
- }
|