bodychecklist.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package bodychecklist
  2. import (
  3. "spaceofcheng/services/models"
  4. "spaceofcheng/services/models/model"
  5. "spaceofcheng/services/utils"
  6. "strconv"
  7. "github.com/go-xorm/xorm"
  8. )
  9. // BodychecklistDAO 当前数据库操作对象
  10. type BodychecklistDAO struct {
  11. ctx *utils.Context
  12. db *xorm.Session
  13. }
  14. // NewBodychecklistDAO New Inst
  15. func NewBodychecklistDAO(ctx *utils.Context) *BodychecklistDAO {
  16. return &BodychecklistDAO{
  17. ctx: ctx,
  18. db: ctx.DB,
  19. }
  20. }
  21. type BodyCheck struct {
  22. model.TaBodyCheck `xorm:"extends"`
  23. CaseName string
  24. Sex string
  25. CustomerName string
  26. Phone string
  27. }
  28. func (m *BodychecklistDAO) GetBodychecklist(phone, customerName, filters string, limit []int) ([]BodyCheck, int64, error) {
  29. var bodycheck []BodyCheck
  30. // if len(filters) > 0 {
  31. // filterString = strings.Join(filters, " and ")
  32. // filterString += " and "
  33. // }
  34. sql := `SELECT
  35. a.*,
  36. b.phone,
  37. b.customer_name,
  38. c.case_name,
  39. CASE
  40. b.sex
  41. WHEN 1 THEN
  42. '男' ELSE '女'
  43. END AS sex
  44. FROM
  45. ta_body_check a
  46. INNER JOIN ta_customer b ON a.user_id = b.customer_id
  47. INNER JOIN sys_case c ON c.case_id = a.case_id
  48. where ` + filters + ` and a.status > ` + strconv.Itoa(models.STATUS_DEL)
  49. if phone != "" {
  50. sql += ` and b.phone = '` + phone + `'`
  51. }
  52. if customerName != "" {
  53. sql += ` and b.customer_name like '%` + customerName + `%'`
  54. }
  55. sql += ` order by a.create_date desc`
  56. total, err := utils.NewPageNaviEngine(m.ctx).GetPageList(&bodycheck, sql, limit)
  57. if err != nil {
  58. return nil, 0, err
  59. }
  60. return bodycheck, total, err
  61. }