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.

77 lines
2.8 KiB

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