wrTrade.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. "net/http"
  9. "strconv"
  10. "github.com/gin-gonic/gin"
  11. )
  12. // Deliverygoods 现货品种表
  13. type Deliverygoods struct {
  14. Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'" binding:"required"` // 交割商品ID(SEQ_DELIVERYGOODS)
  15. Deliverygoodscode string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'" binding:"required"` // 交割商品代码
  16. Deliverygoodsname string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 交割商品名称
  17. Goodsunitid int64 `json:"goodsunitid" xorm:"'GOODSUNITID'"` // 交割商品单位ID
  18. Deliverygoodstype int64 `json:"deliverygoodstype" xorm:"'DELIVERYGOODSTYPE'"` // 交割商品类型: 1-整装不拆分 2-散装记录明细 3:整装拆分 4:散装不记录明细
  19. Standardqty int64 `json:"standardqty" xorm:"'STANDARDQTY'"` // 标准数量(库位数量) [标准品特有]
  20. Standardqtyrange float64 `json:"standardqtyrange" xorm:"'STANDARDQTYRANGE'"` // 标准数量偏差范围 [标准品特有]
  21. Issplit int64 `json:"issplit" xorm:"'ISSPLIT'"` // 是否拆分 - 0:不拆分 1:拆分 [整装] 0:不记录明细 1:记录明细 [散货] - 作废整装时不拆分,则标准数量=合约单位;拆分时标准数量为合约单位的整数倍;整装时必须记录明细表数据
  22. Agreeunit int64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位[散货时默认为1, 整装时默认为标准数量]
  23. Qtydecimalplace int64 `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 成交量小数位
  24. Categoryid int64 `json:"categoryid" xorm:"'CATEGORYID'"` // 类别ID(SEQ_WRCATEGORY)
  25. }
  26. // TableName is DELIVERYGOODS
  27. func (Deliverygoods) TableName() string {
  28. return "DELIVERYGOODS"
  29. }
  30. // Wrcategory 仓单分类表
  31. type Wrcategory struct {
  32. Categoryid int64 `json:"categoryid" xorm:"'CATEGORYID'" binding:"required"` // 类别ID(SEQ_WRCATEGORY)
  33. Categoryname string `json:"categoryname" xorm:"'CATEGORYNAME'"` // 类别名称
  34. Parentcategoryid int64 `json:"parentcategoryid" xorm:"'PARENTCATEGORYID'"` // 父类别ID
  35. Categorydesc string `json:"categorydesc" xorm:"'CATEGORYDESC'"` // 类别描述
  36. Iconurl string `json:"iconurl" xorm:"'ICONURL'"` // 图标地址
  37. Deliverygoods []Deliverygoods // 所包含现货种类信息
  38. }
  39. // TableName is WRCATEGORY
  40. func (Wrcategory) TableName() string {
  41. return "WRCATEGORY"
  42. }
  43. // GetAllDeliveryGoods 获取带仓单分类的种类信息
  44. // @Summary 获取带仓单分类的种类信息
  45. // @Produce json
  46. // @Security ApiKeyAuth
  47. // @Success 200 {object} app.Response
  48. // @Failure 500 {object} app.Response
  49. // @Router /WRTrade/GetAllDeliveryGoods [get]
  50. // @Tags 仓单贸易
  51. func GetAllDeliveryGoods(c *gin.Context) {
  52. appG := app.Gin{C: c}
  53. engine := db.GetEngine()
  54. // 获取品种(交割商品)信息
  55. deliveryGoodses := make([]Deliverygoods, 0)
  56. if err := engine.Where("IsValid=1").And("categoryid<>0").Find(&deliveryGoodses); err != nil {
  57. // 查询失败
  58. logger.GetLogger().Errorf("GetAllDeliveryGoods failed: %s", err.Error())
  59. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  60. return
  61. }
  62. // 获取与品种相关的所有仓单分类信息
  63. // 当前种品所相关的分类ID
  64. ids := ""
  65. for _, deliveryGoods := range deliveryGoodses {
  66. if ids == "" {
  67. ids = strconv.FormatInt(deliveryGoods.Categoryid, 10)
  68. } else {
  69. ids += "," + strconv.FormatInt(deliveryGoods.Categoryid, 10)
  70. }
  71. }
  72. // 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;
  73. // 查询当前所有品种信息
  74. var wrcategorys []Wrcategory
  75. 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 {
  76. // 查询失败
  77. logger.GetLogger().Errorf("GetAllDeliveryGoods failed: %s", err.Error())
  78. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  79. return
  80. }
  81. // 构建分类与品种的从属关系
  82. appG.Response(http.StatusOK, e.SUCCESS, deliveryGoodses)
  83. }