GoodsIntroductionDao.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package manage
  2. import (
  3. "demo/configs"
  4. "demo/data/domain"
  5. "demo/data/domain/vo"
  6. )
  7. func GetByIdGoodsIntroduction(id int) (domain.GoodsIntroduction, error) {
  8. var goodsIntroduction domain.GoodsIntroduction
  9. _, err := configs.Engine.Where("id = ?", id).Get(&goodsIntroduction)
  10. if err != nil {
  11. return goodsIntroduction, err
  12. }
  13. return goodsIntroduction, nil
  14. }
  15. func GetInIdListGoodsIntroduction(ids []int) ([]domain.GoodsIntroduction, error) {
  16. rows, err := configs.Engine.In("id", ids).Rows(&domain.GoodsIntroduction{})
  17. if err != nil {
  18. return make([]domain.GoodsIntroduction, 0), err
  19. }
  20. defer rows.Close()
  21. var list []domain.GoodsIntroduction
  22. for rows.Next() {
  23. var u domain.GoodsIntroduction
  24. list = append(list, u)
  25. }
  26. return list, nil
  27. }
  28. func GetListGoodsIntroduction(goodsIntroduction domain.GoodsIntroduction, pageNum, pageSize int) (vo.BaseListVo, error) {
  29. rows, err := configs.Engine.Limit(pageSize, (pageNum-1)*pageSize).Desc("id").Rows(&goodsIntroduction)
  30. var vo vo.BaseListVo
  31. if err != nil {
  32. return vo, err
  33. }
  34. vo.PageNum = pageNum
  35. vo.PageSize = pageSize
  36. vo.List = make([]any, 0)
  37. for rows.Next() {
  38. var u domain.GoodsIntroduction
  39. rows.Scan(&u)
  40. vo.List = append(vo.List, u)
  41. }
  42. //查询数量
  43. count, err := configs.Engine.Count(&goodsIntroduction)
  44. vo.Total = int(count)
  45. return vo, nil
  46. }
  47. func SaveGoodsIntroduction(goodsIntroduction *domain.GoodsIntroduction) (domain.GoodsIntroduction, error) {
  48. _, err := configs.Engine.Insert(&goodsIntroduction)
  49. if err != nil {
  50. return *goodsIntroduction, err
  51. }
  52. return *goodsIntroduction, nil
  53. }
  54. func SetGoodsIntroduction(goodsIntroductionMap map[string]interface{}, id int) (domain.GoodsIntroduction, bool, error) {
  55. var goodsIntroduction domain.GoodsIntroduction
  56. _, err := configs.Engine.Table("goods_introduction").Where("id = ?", id).Update(goodsIntroductionMap)
  57. if err != nil {
  58. return goodsIntroduction, false, err
  59. }
  60. return goodsIntroduction, true, nil
  61. }
  62. func DeleteGoodsIntroduction(goodsIntroduction domain.GoodsIntroduction) bool {
  63. i, err := configs.Engine.Where("id = ?", goodsIntroduction.Id).Delete(&goodsIntroduction)
  64. if err != nil {
  65. return false
  66. }
  67. return i > 0
  68. }