You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.5 KiB

  1. package service
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. "gin-vue-admin/model/request"
  6. )
  7. // @title CreateExaCustomer
  8. // @description create a customer, 创建用户
  9. // @param e model.ExaCustomer
  10. // @auth (2020/04/05 20:22)
  11. // @return err error
  12. func CreateExaCustomer(e model.ExaCustomer) (err error) {
  13. err = global.GVA_DB.Create(&e).Error
  14. return err
  15. }
  16. // @title DeleteFileChunk
  17. // @description delete a customer, 删除用户
  18. // @auth (2020/04/05 20:22)
  19. // @param e model.ExaCustomer
  20. // @return error
  21. func DeleteExaCustomer(e model.ExaCustomer) (err error) {
  22. err = global.GVA_DB.Delete(e).Error
  23. return err
  24. }
  25. // @title UpdateExaCustomer
  26. // @description update a customer, 更新用户
  27. // @param e *model.ExaCustomer
  28. // @auth (2020/04/05 20:22)
  29. // @return error
  30. func UpdateExaCustomer(e *model.ExaCustomer) (err error) {
  31. err = global.GVA_DB.Save(e).Error
  32. return err
  33. }
  34. // @title GetExaCustomer
  35. // @description get the info of a costumer , 获取用户信息
  36. // @auth (2020/04/05 20:22)
  37. // @param id uint
  38. // @return error
  39. // @return customer ExaCustomer
  40. func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) {
  41. err = global.GVA_DB.Where("id = ?", id).First(&customer).Error
  42. return
  43. }
  44. // @title GetCustomerInfoList
  45. // @description get customer list by pagination, 分页获取用户列表
  46. // @auth (2020/04/05 20:22)
  47. // @param sysUserAuthorityID string
  48. // @param info PageInfo
  49. // @return error
  50. func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) {
  51. limit := info.PageSize
  52. offset := info.PageSize * (info.Page - 1)
  53. db := global.GVA_DB.Model(&model.ExaCustomer{})
  54. var a model.SysAuthority
  55. a.AuthorityId = sysUserAuthorityID
  56. err, auth := GetAuthorityInfo(a)
  57. var dataId []string
  58. for _, v := range auth.DataAuthorityId {
  59. dataId = append(dataId, v.AuthorityId)
  60. }
  61. var CustomerList []model.ExaCustomer
  62. err = db.Where("sys_user_authority_id in (?)", dataId).Count(&total).Error
  63. if err != nil {
  64. return err, CustomerList, total
  65. } else {
  66. err = db.Limit(limit).Offset(offset).Preload("SysUser").Where("sys_user_authority_id in (?)", dataId).Find(&CustomerList).Error
  67. }
  68. return err, CustomerList, total
  69. }