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.

81 lines
2.6 KiB

  1. package service
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. "gin-vue-admin/model/request"
  6. )
  7. //@author: [piexlmax](https://github.com/piexlmax)
  8. //@function: CreateSysDictionaryDetail
  9. //@description: 创建字典详情数据
  10. //@param: sysDictionaryDetail model.SysDictionaryDetail
  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. //@author: [piexlmax](https://github.com/piexlmax)
  17. //@function: DeleteSysDictionaryDetail
  18. //@description: 删除字典详情数据
  19. //@param: sysDictionaryDetail model.SysDictionaryDetail
  20. //@return: err error
  21. func DeleteSysDictionaryDetail(sysDictionaryDetail model.SysDictionaryDetail) (err error) {
  22. err = global.GVA_DB.Delete(&sysDictionaryDetail).Error
  23. return err
  24. }
  25. //@author: [piexlmax](https://github.com/piexlmax)
  26. //@function: UpdateSysDictionaryDetail
  27. //@description: 更新字典详情数据
  28. //@param: sysDictionaryDetail *model.SysDictionaryDetail
  29. //@return: err error
  30. func UpdateSysDictionaryDetail(sysDictionaryDetail *model.SysDictionaryDetail) (err error) {
  31. err = global.GVA_DB.Save(sysDictionaryDetail).Error
  32. return err
  33. }
  34. //@author: [piexlmax](https://github.com/piexlmax)
  35. //@function: GetSysDictionaryDetail
  36. //@description: 根据id获取字典详情单条数据
  37. //@param: id uint
  38. //@return: err error, sysDictionaryDetail model.SysDictionaryDetail
  39. func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail model.SysDictionaryDetail) {
  40. err = global.GVA_DB.Where("id = ?", id).First(&sysDictionaryDetail).Error
  41. return
  42. }
  43. //@author: [piexlmax](https://github.com/piexlmax)
  44. //@function: GetSysDictionaryDetailInfoList
  45. //@description: 分页获取字典详情列表
  46. //@param: info request.SysDictionaryDetailSearch
  47. //@return: err error
  48. func GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int64) {
  49. limit := info.PageSize
  50. offset := info.PageSize * (info.Page - 1)
  51. // 创建db
  52. db := global.GVA_DB.Model(&model.SysDictionaryDetail{})
  53. var sysDictionaryDetails []model.SysDictionaryDetail
  54. // 如果有条件搜索 下方会自动创建搜索语句
  55. if info.Label != "" {
  56. db = db.Where("label LIKE ?", "%"+info.Label+"%")
  57. }
  58. if info.Value != 0 {
  59. db = db.Where("value = ?", info.Value)
  60. }
  61. if info.Status != nil {
  62. db = db.Where("status = ?", info.Status)
  63. }
  64. if info.SysDictionaryID != 0 {
  65. db = db.Where("sys_dictionary_id = ?", info.SysDictionaryID)
  66. }
  67. err = db.Count(&total).Error
  68. err = db.Limit(limit).Offset(offset).Find(&sysDictionaryDetails).Error
  69. return err, sysDictionaryDetails, total
  70. }