wrTrade.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Package wrtrade 仓单贸易
  2. package wrtrade
  3. import (
  4. "mtp2_if/db"
  5. "mtp2_if/global/app"
  6. "mtp2_if/global/e"
  7. "mtp2_if/logger"
  8. "mtp2_if/models"
  9. "net/http"
  10. "strconv"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // GetAllDeliveryGoods 获取带仓单分类的种类信息
  14. // @Summary 获取带仓单分类的种类信息
  15. // @Produce json
  16. // @Security ApiKeyAuth
  17. // @Success 200 {object} app.Response
  18. // @Failure 500 {object} app.Response
  19. // @Router /WRTrade/GetAllDeliveryGoods [get]
  20. // @Tags 仓单贸易
  21. // @Summary 获取带仓单分类的种类信息
  22. // @Produce json
  23. // @Security ApiKeyAuth
  24. // @Success 200 {object} app.Response
  25. // @Failure 500 {object} app.Response
  26. // @Router /WRTrade/GetAllDeliveryGoods [get]
  27. // @Tags 仓单贸易
  28. func GetAllDeliveryGoods(c *gin.Context) {
  29. appG := app.Gin{C: c}
  30. engine := db.GetEngine()
  31. // 获取品种(交割商品)信息
  32. deliveryGoodses := make([]models.Deliverygoods, 0)
  33. if err := engine.Where("IsValid=1").And("categoryid<>0").Find(&deliveryGoodses); err != nil {
  34. // 查询失败
  35. logger.GetLogger().Errorf("GetAllDeliveryGoods failed: %s", err.Error())
  36. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  37. return
  38. }
  39. // 获取与品种相关的所有仓单分类信息
  40. // 当前种品所相关的分类ID
  41. ids := ""
  42. for _, deliveryGoods := range deliveryGoodses {
  43. if ids == "" {
  44. ids = strconv.FormatInt(int64(deliveryGoods.Categoryid), 10)
  45. } else {
  46. ids += "," + strconv.FormatInt(int64(deliveryGoods.Categoryid), 10)
  47. }
  48. }
  49. // SELECT w.categoryid,w.categoryname,w.parentcategoryid,w.categorydesc,w.iconurl FROM WRCategory w START WITH Categoryid in (2,2,4) CONNECT BY PRIOR ParentCategoryID = Categoryid;
  50. // 查询当前所有品种信息
  51. var wrcategorys []models.Wrcategory
  52. if err := engine.SQL("SELECT w.categoryid,w.categoryname,w.parentcategoryid,w.categorydesc,w.iconurl FROM WRCategory w START WITH Categoryid in (?) CONNECT BY PRIOR ParentCategoryID = Categoryid", ids).Find(&wrcategorys); err != nil {
  53. // 查询失败
  54. logger.GetLogger().Errorf("GetAllDeliveryGoods failed: %s", err.Error())
  55. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  56. return
  57. }
  58. // 构建分类与品种的从属关系
  59. appG.Response(http.StatusOK, e.SUCCESS, deliveryGoodses)
  60. }