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.

86 lines
3.1 KiB

3 years ago
3 years ago
  1. package system
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  5. "github.com/flipped-aurora/gin-vue-admin/server/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.GVA_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.GVA_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.GVA_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: err error, sysDictionaryDetail model.SysDictionaryDetail
  40. func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail system.SysDictionaryDetail) {
  41. err = global.GVA_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: err error, list interface{}, total int64
  49. func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int64) {
  50. limit := info.PageSize
  51. offset := info.PageSize * (info.Page - 1)
  52. // 创建db
  53. db := global.GVA_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).Find(&sysDictionaryDetails).Error
  73. return err, sysDictionaryDetails, total
  74. }