sys_dictionary_detail.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package system
  2. import (
  3. "lc-base-frame/global"
  4. "lc-base-frame/model/system"
  5. "lc-base-frame/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. func (dictionaryDetailService *DictionaryDetailService) CreateSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) {
  14. err = global.Db.Create(&sysDictionaryDetail).Error
  15. return err
  16. }
  17. //@author: [piexlmax](https://github.com/piexlmax)
  18. //@function: DeleteSysDictionaryDetail
  19. //@description: 删除字典详情数据
  20. //@param: sysDictionaryDetail model.SysDictionaryDetail
  21. //@return: err error
  22. func (dictionaryDetailService *DictionaryDetailService) DeleteSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) {
  23. err = global.Db.Delete(&sysDictionaryDetail).Error
  24. return err
  25. }
  26. //@author: [piexlmax](https://github.com/piexlmax)
  27. //@function: UpdateSysDictionaryDetail
  28. //@description: 更新字典详情数据
  29. //@param: sysDictionaryDetail *model.SysDictionaryDetail
  30. //@return: err error
  31. func (dictionaryDetailService *DictionaryDetailService) UpdateSysDictionaryDetail(sysDictionaryDetail *system.SysDictionaryDetail) (err error) {
  32. err = global.Db.Save(sysDictionaryDetail).Error
  33. return err
  34. }
  35. //@author: [piexlmax](https://github.com/piexlmax)
  36. //@function: GetSysDictionaryDetail
  37. //@description: 根据id获取字典详情单条数据
  38. //@param: id uint
  39. //@return: sysDictionaryDetail system.SysDictionaryDetail, err error
  40. func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetail(id uint) (sysDictionaryDetail system.SysDictionaryDetail, err error) {
  41. err = global.Db.Where("id = ?", id).First(&sysDictionaryDetail).Error
  42. return
  43. }
  44. //@author: [piexlmax](https://github.com/piexlmax)
  45. //@function: GetSysDictionaryDetailInfoList
  46. //@description: 分页获取字典详情列表
  47. //@param: info request.SysDictionaryDetailSearch
  48. //@return: list interface{}, total int64, err error
  49. func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (list interface{}, total int64, err error) {
  50. limit := info.PageSize
  51. offset := info.PageSize * (info.Page - 1)
  52. // 创建db
  53. db := global.Db.Model(&system.SysDictionaryDetail{})
  54. var sysDictionaryDetails []system.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. if err != nil {
  70. return
  71. }
  72. err = db.Limit(limit).Offset(offset).Order("sort").Find(&sysDictionaryDetails).Error
  73. return sysDictionaryDetails, total, err
  74. }