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.

84 lines
3.0 KiB

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