2
3

paymentselectService.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package paymentselect
  2. import (
  3. . "dashoo.cn/utils/db"
  4. "github.com/go-xorm/xorm"
  5. "strconv"
  6. )
  7. type PaymentSelectService struct {
  8. ServiceBase
  9. }
  10. func GetPaymentSelectService(xormEngine *xorm.Engine) *PaymentSelectService {
  11. s := new(PaymentSelectService)
  12. s.DBE = xormEngine
  13. return s
  14. }
  15. func (s *PaymentSelectService) GetPaymentselectList(pageIndex, itemsPerPage int64, order string, asc string, entitiesPtr interface{}, where string) (total int64) {
  16. var resultsSlice []map[string][]byte
  17. sqlconunt := "SELECT COUNT(p.Id) FROM OilPaymentInfo p " +
  18. "LEFT JOIN OilSupplier s ON p.SupplierId = s.Id "+
  19. "LEFT JOIN OilSupplierCert c ON p.SupplierCertId = c.Id " +
  20. "WHERE " + where
  21. sql := "SELECT c.AccessCardNo,s.SupplierName,c.SupplierTypeName,p.PayDate, " +
  22. "sum(case when p.PayType = '1' then Amount else 0 end) as Access, " +
  23. "sum(case when p.PayType = '2' then Amount else 0 end) as Annual, " +
  24. "sum(case when p.PayType = '3' then Amount else 0 end) as Addition, " +
  25. "sum(p.Amount) as Sums, " +
  26. "min(p.Remark) as Remarks " +
  27. "FROM OilPaymentInfo p " +
  28. "LEFT JOIN OilSupplier s ON p.SupplierId = s.Id "+
  29. "LEFT JOIN OilSupplierCert c ON p.SupplierCertId = c.Id " +
  30. "group by c.AccessCardNo,s.SupplierName,c.SupplierTypeName,p.PayDate,s.CommercialNo " +
  31. "having " + where +
  32. " Order By " + order + asc + " Limit " + strconv.Itoa(int(itemsPerPage)) +" OFFSET " + strconv.Itoa((int(pageIndex)-1)*int(itemsPerPage))
  33. s.DBE.SQL(sql).Find(entitiesPtr)
  34. resultsSlice, _ = s.DBE.Query(sqlconunt)
  35. if len(resultsSlice) > 0 {
  36. results := resultsSlice[0]
  37. for _, value := range results {
  38. total, _ = strconv.ParseInt(string(value), 10, 64)
  39. break
  40. }
  41. }
  42. return total
  43. }
  44. //以上除查询功能外已经稳定,别碰!!
  45. func (s *PaymentSelectService) GetPaymentselectSumList( order string, asc string, entitiesPtr interface{}, where string) {
  46. sql := "SELECT c.SupplierTypeName, " +
  47. "sum(case when p.PayType = '1' then Amount else 0 end) as Access, " +
  48. "sum(case when p.PayType = '2' then Amount else 0 end) as Annual, " +
  49. "sum(case when p.PayType = '3' then Amount else 0 end) as Addition, " +
  50. "sum(p.Amount) as Sums " +
  51. "FROM OilPaymentInfo p " +
  52. "LEFT JOIN OilSupplier s ON p.SupplierId = s.Id "+
  53. "LEFT JOIN OilSupplierCert c ON p.SupplierCertId = c.Id " + where +
  54. "group by c.SupplierTypeName " +
  55. " Order By " + order + asc
  56. s.DBE.SQL(sql).Find(entitiesPtr)
  57. }