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.

79 lines
2.8 KiB

  1. package autocode
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
  6. )
  7. type AutoCodeExampleService struct {
  8. }
  9. //@author: [piexlmax](https://github.com/piexlmax)
  10. //@function: CreateAutoCodeExample
  11. //@description: 创建自动化示例数据
  12. //@param: autoCodeExampleService *AutoCodeExampleService
  13. //@return: err error
  14. func (autoCodeExampleService *AutoCodeExampleService) CreateAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) {
  15. err = global.GVA_DB.Create(&autoCodeExample).Error
  16. return err
  17. }
  18. //@author: [piexlmax](https://github.com/piexlmax)
  19. //@function: DeleteAutoCodeExample
  20. //@description: 删除自动化示例数据
  21. //@param: autoCodeExample autocode.AutoCodeExample
  22. //@return: err error
  23. func (autoCodeExampleService *AutoCodeExampleService) DeleteAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) {
  24. err = global.GVA_DB.Delete(&autoCodeExample).Error
  25. return err
  26. }
  27. //@author: [piexlmax](https://github.com/piexlmax)
  28. //@function: UpdateAutoCodeExample
  29. //@description: 更新自动化示例数据
  30. //@param: autoCodeExample *autocode.AutoCodeExample
  31. //@return: err error
  32. func (autoCodeExampleService *AutoCodeExampleService) UpdateAutoCodeExample(autoCodeExample *autocode.AutoCodeExample) (err error) {
  33. err = global.GVA_DB.Save(autoCodeExample).Error
  34. return err
  35. }
  36. //@author: [piexlmax](https://github.com/piexlmax)
  37. //@function: GetAutoCodeExampleDetail
  38. //@description: 根据id获取自动化示例数据
  39. //@param: id uint
  40. //@return: err error, autoCodeExample autocode.AutoCodeExample
  41. func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExample(id uint) (err error, autoCodeExample autocode.AutoCodeExample) {
  42. err = global.GVA_DB.Where("id = ?", id).First(&autoCodeExample).Error
  43. return
  44. }
  45. //@author: [piexlmax](https://github.com/piexlmax)
  46. //@function: GetAutoCodeExampleInfoList
  47. //@description: 分页获取自动化示例数据
  48. //@param: info request.AutoCodeExampleSearch
  49. //@return: err error, list interface{}, total int64
  50. func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExampleInfoList(info request.AutoCodeExampleSearch) (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(&autocode.AutoCodeExample{})
  55. var autoCodeExamples []autocode.AutoCodeExample
  56. // 如果有条件搜索 下方会自动创建搜索语句
  57. if info.AutoCodeExampleField != "" {
  58. db = db.Where("label LIKE ?", "%"+info.AutoCodeExampleField+"%")
  59. }
  60. err = db.Count(&total).Error
  61. if err != nil {
  62. return
  63. }
  64. err = db.Limit(limit).Offset(offset).Find(&autoCodeExamples).Error
  65. return err, autoCodeExamples, total
  66. }