wrTrade.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // Wrcategory 仓单分类表
  14. type Wrcategory struct {
  15. Categoryid int64 `json:"categoryid" xorm:"'CATEGORYID'" binding:"required"` // 类别ID(SEQ_WRCATEGORY)
  16. Categoryname string `json:"categoryname" xorm:"'CATEGORYNAME'"` // 类别名称
  17. Parentcategoryid int64 `json:"parentcategoryid" xorm:"'PARENTCATEGORYID'"` // 父类别ID
  18. Categorydesc string `json:"categorydesc" xorm:"'CATEGORYDESC'"` // 类别描述
  19. Iconurl string `json:"iconurl" xorm:"'ICONURL'"` // 图标地址
  20. Deliverygoods []models.Deliverygoods // 所包含现货种类信息
  21. }
  22. // TableName is WRCATEGORY
  23. func (Wrcategory) TableName() string {
  24. return "WRCATEGORY"
  25. }
  26. // GetAllDeliveryGoods 获取带仓单分类的种类信息
  27. // @Summary 获取带仓单分类的种类信息
  28. // @Produce json
  29. // @Security ApiKeyAuth
  30. // @Success 200 {object} app.Response
  31. // @Failure 500 {object} app.Response
  32. // @Router /WRTrade/GetAllDeliveryGoods [get]
  33. // @Tags 仓单贸易
  34. // @Summary 获取带仓单分类的种类信息
  35. // @Produce json
  36. // @Security ApiKeyAuth
  37. // @Success 200 {object} app.Response
  38. // @Failure 500 {object} app.Response
  39. // @Router /WRTrade/GetAllDeliveryGoods [get]
  40. // @Tags 仓单贸易
  41. func GetAllDeliveryGoods(c *gin.Context) {
  42. appG := app.Gin{C: c}
  43. engine := db.GetEngine()
  44. // 获取品种(交割商品)信息
  45. deliveryGoodses := make([]models.Deliverygoods, 0)
  46. if err := engine.Where("IsValid=1").And("categoryid<>0").Find(&deliveryGoodses); err != nil {
  47. // 查询失败
  48. logger.GetLogger().Errorf("GetAllDeliveryGoods failed: %s", err.Error())
  49. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  50. return
  51. }
  52. // 获取与品种相关的所有仓单分类信息
  53. // 当前种品所相关的分类ID
  54. ids := ""
  55. for _, deliveryGoods := range deliveryGoodses {
  56. if ids == "" {
  57. ids = strconv.FormatInt(int64(deliveryGoods.Categoryid), 10)
  58. } else {
  59. ids += "," + strconv.FormatInt(int64(deliveryGoods.Categoryid), 10)
  60. }
  61. }
  62. // 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;
  63. // 查询当前所有品种信息
  64. var wrcategorys []Wrcategory
  65. 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 {
  66. // 查询失败
  67. logger.GetLogger().Errorf("GetAllDeliveryGoods failed: %s", err.Error())
  68. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  69. return
  70. }
  71. // 构建分类与品种的从属关系
  72. appG.Response(http.StatusOK, e.SUCCESS, deliveryGoodses)
  73. }