project.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package admin
  2. import (
  3. "fmt"
  4. "github.com/shopspring/decimal"
  5. "server/dao"
  6. "server/model/common/request"
  7. "time"
  8. )
  9. type ProjectService struct{}
  10. func (ps *ProjectService) QueryProjectList(info request.SearchProject) (list interface{}, total int64, err error) {
  11. limit := info.PageInfo.PageSize
  12. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  13. project, total, err := dao.QueryProjectList(limit, offset, info.State, info.Name, info.Time)
  14. for i, p := range project {
  15. collection, err := dao.QueryCollection(p.Code)
  16. if err != nil {
  17. return nil, total, err
  18. }
  19. project[i].Collection = collection
  20. }
  21. return project, total, err
  22. }
  23. func (ps *ProjectService) QueryProjectByCode(code string) (project dao.Project, err error) {
  24. project, err = dao.QueryProjectByCode(code)
  25. if err != nil {
  26. return
  27. }
  28. files, err := dao.QueryFilesByCode(code)
  29. if err != nil {
  30. return
  31. }
  32. project.Files = files
  33. return project, err
  34. }
  35. func (ps *ProjectService) QueryFileList(info request.SearchProjectFileList) (list interface{}, total int64, err error) {
  36. limit := info.PageInfo.PageSize
  37. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  38. files, total, err := dao.QueryFileList(limit, offset, info.Genre, info.Code, info.Name)
  39. return files, total, err
  40. }
  41. func (ps *ProjectService) QueryFilesByNameOrGenre(info request.SearchProjectFileList) ([]dao.ProjectFile, error) {
  42. return dao.QueryFilesByNameOrGenre(info.Genre, info.Code, info.Name)
  43. }
  44. func (ps *ProjectService) QueryAllProject() ([]dao.Project, error) {
  45. return dao.QueryAllProject()
  46. }
  47. func (ps *ProjectService) QueryProjectsInfo() (sum decimal.Decimal, totalProject, completeProject, unCompleteProject int, err error) {
  48. projects, err := dao.QueryAllProject()
  49. if err != nil {
  50. return
  51. }
  52. for _, project := range projects {
  53. totalProject++
  54. if project.State == 3 {
  55. completeProject++
  56. }
  57. sum = sum.Add(project.Price)
  58. }
  59. fmt.Printf("%y", sum)
  60. unCompleteProject = totalProject - completeProject
  61. return
  62. }
  63. func (ps *ProjectService) QueryProjectState() ([]dao.ProjectState, error) {
  64. return dao.QueryProjectState()
  65. }
  66. func (ps *ProjectService) QueryWorkingHours(code string) ([]dao.ProjectWorkingHours, error) {
  67. return dao.QueryWorkingHours(code)
  68. }
  69. func (ps *ProjectService) QueryCollections(code string) ([]dao.Collection, error) {
  70. return dao.QueryCollection(code)
  71. }
  72. func (ps *ProjectService) QueryReimbursementList(info request.SearchProjectList) (list interface{}, total int64, err error) {
  73. limit := info.PageInfo.PageSize
  74. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  75. return dao.QueryReimbursementList(limit, offset, info.Code, info.Name)
  76. }
  77. func (ps *ProjectService) QueryReimbursement(code string) ([]dao.Reimbursement, error) {
  78. reimbursements, err := dao.QueryReimbursement(code)
  79. if err != nil {
  80. return nil, err
  81. }
  82. for i, reimbursement := range reimbursements {
  83. details, err := dao.QueryFeeDetails(int(reimbursement.ID))
  84. if err != nil {
  85. return nil, err
  86. }
  87. reimbursements[i].FeeDetails = details
  88. }
  89. return reimbursements, err
  90. }
  91. func (ps *ProjectService) CreateProject(project dao.Project) error {
  92. return project.CreateProject()
  93. }
  94. func (ps *ProjectService) CreateProjectFile(projectFile dao.ProjectFile) error {
  95. return projectFile.CreateFile()
  96. }
  97. func (ps *ProjectService) CreateProjectState(projectState dao.ProjectState) error {
  98. return projectState.CreateProjectState()
  99. }
  100. func (ps *ProjectService) CreateOrUpdateWorkingHours(workingHours dao.ProjectWorkingHours) error {
  101. // 查询是否已有工时
  102. hours, err := dao.QueryWorkingHoursByCode(workingHours.ProjectCode, workingHours.People)
  103. if err != nil { // 创建时没有id 判断是创建还是修改
  104. // 新增工时+已有工时
  105. zongHours := hours.Days + workingHours.Days
  106. workingHours.Days = zongHours
  107. workingHours.Price = hours.Price
  108. err = workingHours.UpdateWorkingHours()
  109. return err
  110. } else {
  111. err := workingHours.CreateWorkingHours()
  112. if err != nil {
  113. return err
  114. }
  115. return err
  116. }
  117. }
  118. func (ps *ProjectService) CreateCollection(collection dao.Collection) error {
  119. return collection.CreateCollection()
  120. }
  121. func (ps *ProjectService) CreateReimbursement(reimbursement dao.Reimbursement) error {
  122. return reimbursement.CreateReimbursement()
  123. }
  124. func (ps *ProjectService) UpdateProject(project dao.Project) error {
  125. if project.State == 3 {
  126. project.CollectionTime = time.Now().Format("2006-01-02 15:04:05")
  127. } else if project.State == 4 || project.State == 5 {
  128. project.EndTime = time.Now().Format("2006-01-02 15:04:05")
  129. }
  130. return project.UpdateProject()
  131. }
  132. func (ps *ProjectService) UpdateProjectState(projectState dao.ProjectState) error {
  133. return projectState.UpdateProjectState()
  134. }
  135. func (ps *ProjectService) UpdateWorkingHours(workingHours dao.ProjectWorkingHours) error {
  136. return workingHours.UpdateWorkingHours()
  137. }
  138. func (ps *ProjectService) UpdateCollection(collection dao.Collection) error {
  139. return collection.UpdateCollection()
  140. }
  141. func (ps *ProjectService) UpdateReimbursement(reimbursement dao.Reimbursement) error {
  142. return reimbursement.UpdateReimbursement()
  143. }
  144. func (ps *ProjectService) DeleteProject(code string) error {
  145. return dao.DeleteProject(code)
  146. }
  147. func (ps *ProjectService) DeleteProjectFile(id uint) error {
  148. return dao.DeleteFile(id)
  149. }
  150. func (ps *ProjectService) DeleteProjectState(projectState dao.ProjectState) error {
  151. return projectState.DeleteProjectState()
  152. }
  153. func (ps *ProjectService) DeleteWorkingHours(workingHours dao.ProjectWorkingHours) error {
  154. return workingHours.DeleteWorkingHours()
  155. }
  156. func (ps *ProjectService) DeleteCollection(collection dao.Collection) error {
  157. return collection.DeleteCollection()
  158. }
  159. func (ps *ProjectService) DeleteReimbursement(reimbursement dao.Reimbursement) error {
  160. return reimbursement.DeleteReimbursement()
  161. }