settle_account_bill.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package settle_account_bill
  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.SettleAccountBillDao
  12. Tenant string
  13. }
  14. // NewSrv 服务初始化
  15. func NewService(tenant string) Service {
  16. return Service{Dao: account.NewSettleAccountBillDao(tenant), Tenant: tenant}
  17. }
  18. // List 会议室列表
  19. func (s Service) List(req model.ListReq) ([]accountModel.SettleAccountBill, int, error) {
  20. entityModel := s.Dao.M
  21. where := "1=1"
  22. if req.Entity != nil {
  23. entity := new(accountModel.SettleAccountBillReq)
  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.Status != "" {
  32. where += fmt.Sprintf(" AND Status='%v'", entity.Status)
  33. }
  34. }
  35. entityModel = entityModel.Where(where)
  36. total, err := entityModel.Count()
  37. if err != nil {
  38. return nil, 0, err
  39. }
  40. if total == 0 {
  41. return nil, 0, nil
  42. }
  43. res, err := entityModel.Page(req.Current, req.Size).Order("settle_account_bill.CreateOn DESC").Fields("settle_account_bill.*").FindAll()
  44. if err != nil {
  45. return nil, 0, err
  46. }
  47. if res.IsEmpty() {
  48. return nil, 0, nil
  49. }
  50. list := make([]accountModel.SettleAccountBill, 0)
  51. err = res.Structs(&list)
  52. if err != nil {
  53. return nil, 0, err
  54. }
  55. return list, total, nil
  56. }