settle_account_main.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package settle_account_main
  2. import (
  3. "fmt"
  4. "github.com/gogf/gf/util/gconv"
  5. "lims_adapter/dao/account"
  6. "lims_adapter/model"
  7. accountModel "lims_adapter/model/account"
  8. )
  9. // Service 会议室服务
  10. type Service struct {
  11. Dao *account.SettleAccountMainDao
  12. Tenant string
  13. }
  14. // NewSrv 服务初始化
  15. func NewService(tenant string) Service {
  16. return Service{Dao: account.NewSettleAccountMainDao(tenant), Tenant: tenant}
  17. }
  18. // List 会议室列表
  19. func (s Service) List(req model.ListReq) ([]accountModel.SettleAccountMain, int, error) {
  20. entityModel := s.Dao.M
  21. where := "1=1"
  22. if req.Entity != nil {
  23. entity := new(accountModel.SettleAccountMainReq)
  24. err := gconv.Struct(req.Entity, entity)
  25. if err != nil {
  26. return nil, 0, err
  27. }
  28. if entity.MainUserId != 0 {
  29. where += fmt.Sprintf(" AND MainUserId='%v'", entity.MainUserId)
  30. }
  31. if entity.AttachUserId != 0 {
  32. where += fmt.Sprintf(" AND AttachUserId='%v'", entity.AttachUserId)
  33. }
  34. if entity.InstrumentId != 0 {
  35. where += fmt.Sprintf(" AND InstrumentId='%v'", entity.InstrumentId)
  36. }
  37. if entity.Status != "" {
  38. where += fmt.Sprintf(" AND Status='%v'", entity.Status)
  39. }
  40. if entity.SettleStatus != "" {
  41. where += fmt.Sprintf(" AND SettleStatus='%v'", entity.SettleStatus)
  42. }
  43. if entity.FeeType != "" {
  44. where += fmt.Sprintf(" AND FeeType='%v'", entity.FeeType)
  45. }
  46. }
  47. entityModel = entityModel.Where(where)
  48. total, err := entityModel.Count()
  49. if err != nil {
  50. return nil, 0, err
  51. }
  52. if total == 0 {
  53. return nil, 0, nil
  54. }
  55. res, err := entityModel.Page(req.Current, req.Size).Order("settle_account_main.CreateOn DESC").Fields("settle_account_main.*").FindAll()
  56. if err != nil {
  57. return nil, 0, err
  58. }
  59. if res.IsEmpty() {
  60. return nil, 0, nil
  61. }
  62. list := make([]accountModel.SettleAccountMain, 0)
  63. err = res.Structs(&list)
  64. if err != nil {
  65. return nil, 0, err
  66. }
  67. return list, total, nil
  68. }