project.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. unCompleteProject = totalProject - completeProject
  60. return
  61. }
  62. func (ps *ProjectService) QueryProjectState() ([]dao.ProjectState, error) {
  63. return dao.QueryProjectState()
  64. }
  65. func (ps *ProjectService) QueryWorkingHours(code string) ([]dao.ProjectWorkingHours, error) {
  66. return dao.QueryWorkingHours(code)
  67. }
  68. func (ps *ProjectService) QueryWorkingHoursList(info request.SearchWorkingHours) (list interface{}, total int64, err error) {
  69. limit := info.PageInfo.PageSize
  70. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  71. return dao.QueryWorkingHoursList(limit, offset, info.People, info.Code, info.Time, info.YearTime)
  72. }
  73. func (ps *ProjectService) QueryWorkingHoursSum(info request.SearchWorkingHours) (list interface{}, total int64, err error) {
  74. limit := info.PageInfo.PageSize
  75. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  76. return dao.QueryWorkingHoursSum(limit, offset, info.People, info.Code, info.Time, info.YearTime)
  77. }
  78. func (ps *ProjectService) QueryCollections(code string) ([]dao.Collection, error) {
  79. return dao.QueryCollection(code)
  80. }
  81. func (ps *ProjectService) QueryCollectionList(info request.SearchProjectList) (list interface{}, total int64, err error) {
  82. limit := info.PageInfo.PageSize
  83. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  84. return dao.QueryCollectionList(limit, offset, info.Code, info.Time)
  85. }
  86. func (ps *ProjectService) QueryReimbursementList(info request.SearchProjectList) (list interface{}, total int64, err error) {
  87. limit := info.PageInfo.PageSize
  88. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  89. reimbursements, total, err := dao.QueryReimbursementList(limit, offset, info.Code, info.Name, info.Time)
  90. if err != nil {
  91. return nil, 0, err
  92. }
  93. for i, reimbursement := range reimbursements {
  94. details, err := dao.QueryFeeDetails(int(reimbursement.ID))
  95. if err != nil {
  96. return nil, 0, err
  97. }
  98. reimbursements[i].FeeDetails = details
  99. }
  100. return reimbursements, total, err
  101. }
  102. func (ps *ProjectService) QueryReimbursement(code string) ([]dao.Reimbursement, error) {
  103. reimbursements, err := dao.QueryReimbursement(code)
  104. if err != nil {
  105. return nil, err
  106. }
  107. for i, reimbursement := range reimbursements {
  108. details, err := dao.QueryFeeDetails(int(reimbursement.ID))
  109. if err != nil {
  110. return nil, err
  111. }
  112. reimbursements[i].FeeDetails = details
  113. }
  114. return reimbursements, err
  115. }
  116. func (ps *ProjectService) CreateProject(project dao.Project) error {
  117. return project.CreateProject()
  118. }
  119. func (ps *ProjectService) CreateProjectFile(projectFile dao.ProjectFile) error {
  120. return projectFile.CreateFile()
  121. }
  122. func (ps *ProjectService) CreateProjectState(projectState dao.ProjectState) error {
  123. return projectState.CreateProjectState()
  124. }
  125. func (ps *ProjectService) CreateOrUpdateWorkingHours(workingHours dao.ProjectWorkingHours) error {
  126. return workingHours.CreateWorkingHours()
  127. }
  128. func (ps *ProjectService) CreateCollection(collection dao.Collection) error {
  129. return collection.CreateCollection()
  130. }
  131. func (ps *ProjectService) CreateReimbursement(reimbursement dao.Reimbursement) error {
  132. return reimbursement.CreateReimbursement()
  133. }
  134. func (ps *ProjectService) UpdateProject(project dao.Project) error {
  135. if project.State == 3 {
  136. project.CollectionTime = time.Now().Format("2006-01-02 15:04:05")
  137. } else if project.State == 4 || project.State == 5 {
  138. project.EndTime = time.Now().Format("2006-01-02 15:04:05")
  139. }
  140. return project.UpdateProject()
  141. }
  142. func (ps *ProjectService) UpdateProjectState(projectState dao.ProjectState) error {
  143. return projectState.UpdateProjectState()
  144. }
  145. func (ps *ProjectService) UpdateWorkingHours(workingHours dao.ProjectWorkingHours) error {
  146. return workingHours.UpdateWorkingHours()
  147. }
  148. func (ps *ProjectService) UpdateCollection(collection dao.Collection) error {
  149. return collection.UpdateCollection()
  150. }
  151. func (ps *ProjectService) UpdateReimbursement(reimbursement dao.Reimbursement) error {
  152. return reimbursement.UpdateReimbursement()
  153. }
  154. func (ps *ProjectService) DeleteProject(code string) error {
  155. files, _ := dao.QueryFilesByCode(code)
  156. if len(files) > 0 {
  157. return fmt.Errorf("项目下存在文件")
  158. }
  159. collection, _ := dao.QueryCollection(code)
  160. if len(collection) > 0 {
  161. return fmt.Errorf("项目下存在收款记录")
  162. }
  163. project, _ := dao.QueryProjectByCode(code)
  164. expenses, _ := dao.QueryExpensesByProjectId(int(project.ID))
  165. if len(expenses) > 0 {
  166. return fmt.Errorf("项目下存在费用记录")
  167. }
  168. return dao.DeleteProject(code)
  169. }
  170. func (ps *ProjectService) DeleteProjectFile(id uint) error {
  171. return dao.DeleteFile(id)
  172. }
  173. func (ps *ProjectService) DeleteProjectState(projectState dao.ProjectState) error {
  174. return projectState.DeleteProjectState()
  175. }
  176. func (ps *ProjectService) DeleteWorkingHours(workingHours dao.ProjectWorkingHours) error {
  177. return workingHours.DeleteWorkingHours()
  178. }
  179. func (ps *ProjectService) DeleteCollection(collection dao.Collection) error {
  180. return collection.DeleteCollection()
  181. }
  182. func (ps *ProjectService) DeleteReimbursement(reimbursement dao.Reimbursement) error {
  183. return reimbursement.DeleteReimbursement()
  184. }