contractService.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package contract
  2. import (
  3. . "dashoo.cn/backend/api/mydb"
  4. "github.com/go-xorm/xorm"
  5. "strconv"
  6. )
  7. type OilContractService struct {
  8. MyServiceBase
  9. }
  10. func GetOilContractService(xormEngine *xorm.Engine) *OilContractService {
  11. s := new(OilContractService)
  12. s.DBE = xormEngine
  13. return s
  14. }
  15. func (s *OilContractService) GetHandOnStatisticsList(queryParam HandOnStatisticsQuery, entitiesPtr interface{}) (total int64) {
  16. if queryParam.PageIndex < 1 {
  17. queryParam.PageIndex = 1
  18. }
  19. if queryParam.ItemsPerPage < 1 {
  20. queryParam.ItemsPerPage = 10
  21. }
  22. // var resultsSlice []map[string][]byte
  23. /*sqlCount := "SELECT COUNT(*) " +
  24. " FROM OilContract a " +
  25. " LEFT JOIN OilContractReview b ON b.ContractId=a.Id " +
  26. " GROUP BY a.SecondUnit "*/
  27. sql := "SELECT c.FullName as SecondUnit, COUNT(DISTINCT a.Id) AS ContractNum, COUNT(DISTINCT b.ContractId) AS HasNum, " +
  28. " COUNT(DISTINCT IF(b.Status = 8, b.ContractId, null)) AS FinishNum, " +
  29. " COUNT(DISTINCT IF(b.Status > 2, b.ContractId, null)) AS ReportedNum, " +
  30. " (COUNT(DISTINCT a.Id) - COUNT(DISTINCT IF(b.Status > 2, b.ContractId, NULL))) AS UnReportNum " +
  31. " FROM OilContract a " +
  32. " LEFT JOIN OilContractReview b ON a.Id = b.ContractId " +
  33. " LEFT JOIN Base_Organize c on SecondUnit = c.Id"
  34. sql += " WHERE a.ImportStatus > 0 and a.Status = 2 "
  35. if queryParam.YearNum > 0 {
  36. sql += " AND " + strconv.Itoa(queryParam.YearNum) + " BETWEEN YEAR(a.StartDate) AND YEAR(a.EndDate)"
  37. }
  38. if queryParam.SupplierType != "" {
  39. sql += " AND a.ContractClass='" + queryParam.SupplierType + "'"
  40. }
  41. sql += " GROUP BY a.SecondUnit "
  42. if queryParam.SecondUnit != "" {
  43. sql += " HAVING c.FullName like '%" + queryParam.SecondUnit + "%'"
  44. }
  45. if queryParam.Order != "" {
  46. sql += " ORDER BY " + queryParam.Prop + " " + queryParam.Order
  47. }
  48. startLimit := 0
  49. endLimit := 10000
  50. var totalCnt int64
  51. totalCnt, _ = s.DBE.SQL(sql).Limit(startLimit, endLimit).FindAndCount(entitiesPtr)
  52. return totalCnt
  53. }
  54. func (s *OilContractService) GetSum1(entitiesPtr interface{}, where string) {
  55. sql := ` select sum(Money) as Money from OilContractMoney`
  56. sql += ` where ` + where
  57. s.DBE.SQL(sql).Get(entitiesPtr)
  58. return
  59. }
  60. func (s *OilContractService) GetList(entitiesPtr interface{}, where string) {
  61. sql := ` select Year,Money from OilContractMoney`
  62. sql += ` where ` + where
  63. s.DBE.SQL(sql).Find(entitiesPtr)
  64. return
  65. }
  66. func (s *OilContractService) GetJoinBySelect1(where string, entityPtr interface{}) {
  67. sql := "select a.Id from OilSupplier a left join OilSupplierCert b ON a.Id = b.SupplierId "
  68. if where != "" {
  69. sql = sql + " Where " + where
  70. }
  71. s.DBE.SQL(sql).Get(entityPtr)
  72. return
  73. }