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.

82 lines
2.8 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 CreateSysDictionaryDetail
  8. // @description create a SysDictionaryDetail
  9. // @param sysDictionaryDetail model.SysDictionaryDetail
  10. // @auth (2020/04/05 20:22)
  11. // @return err error
  12. func CreateSysDictionaryDetail(sysDictionaryDetail model.SysDictionaryDetail) (err error) {
  13. err = global.GVA_DB.Create(&sysDictionaryDetail).Error
  14. return err
  15. }
  16. // @title DeleteSysDictionaryDetail
  17. // @description delete a SysDictionaryDetail
  18. // @auth (2020/04/05 20:22)
  19. // @param sysDictionaryDetail model.SysDictionaryDetail
  20. // @return error
  21. func DeleteSysDictionaryDetail(sysDictionaryDetail model.SysDictionaryDetail) (err error) {
  22. err = global.GVA_DB.Delete(sysDictionaryDetail).Error
  23. return err
  24. }
  25. // @title UpdateSysDictionaryDetail
  26. // @description update a SysDictionaryDetail
  27. // @param sysDictionaryDetail *model.SysDictionaryDetail
  28. // @auth (2020/04/05 20:22)
  29. // @return error
  30. func UpdateSysDictionaryDetail(sysDictionaryDetail *model.SysDictionaryDetail) (err error) {
  31. err = global.GVA_DB.Save(sysDictionaryDetail).Error
  32. return err
  33. }
  34. // @title GetSysDictionaryDetail
  35. // @description get the info of a SysDictionaryDetail
  36. // @auth (2020/04/05 20:22)
  37. // @param id uint
  38. // @return error
  39. // @return SysDictionaryDetail SysDictionaryDetail
  40. func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail model.SysDictionaryDetail) {
  41. err = global.GVA_DB.Where("id = ?", id).First(&sysDictionaryDetail).Error
  42. return
  43. }
  44. // @title GetSysDictionaryDetailInfoList
  45. // @description get SysDictionaryDetail list by pagination, 分页获取用户列表
  46. // @auth (2020/04/05 20:22)
  47. // @param info PageInfo
  48. // @return error
  49. func GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int) {
  50. limit := info.PageSize
  51. offset := info.PageSize * (info.Page - 1)
  52. // 创建db
  53. db := global.GVA_DB.Model(&model.SysDictionaryDetail{})
  54. var sysDictionaryDetails []model.SysDictionaryDetail
  55. // 如果有条件搜索 下方会自动创建搜索语句
  56. if info.Label != "" {
  57. db = db.Where("label LIKE ?", "%"+info.Label+"%")
  58. }
  59. if info.Value != 0 {
  60. db = db.Where("value = ?", info.Value)
  61. }
  62. if info.Status != nil {
  63. db = db.Where("status = ?", info.Status)
  64. }
  65. if info.SysDictionaryID != 0 {
  66. db = db.Where("sys_dictionary_id = ?", info.SysDictionaryID)
  67. }
  68. err = db.Count(&total).Error
  69. err = db.Limit(limit).Offset(offset).Find(&sysDictionaryDetails).Error
  70. return err, sysDictionaryDetails, total
  71. }