ermcpSpotGoodsPrice.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/4/12 10:07
  4. * @Modify : 2021/4/12 10:07
  5. */
  6. package models
  7. import (
  8. "mtp2_if/db"
  9. "mtp2_if/mtpcache"
  10. "mtp2_if/utils"
  11. )
  12. // ErmcpSpotGoodsPrice 现货市价
  13. type ErmcpSpotGoodsPrice struct {
  14. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
  15. SPOTGOODSMODELID int32 `json:"spotgoodsmodelid" xorm:"'SPOTGOODSMODELID'"` // 现货品类ID(通用则为0)
  16. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID(通用则为0, 不为0则须先有品类ID)
  17. CURRENCYID int64 `json:"currencyid" xorm:"'CURRENCYID'"` // 报价货币ID
  18. SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"'SPOTGOODSPRICE'"` // 现货价格
  19. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  20. OPERATESRC int32 `json:"operatesrc" xorm:"'OPERATESRC'"` // 最后操作来源 - 1:管理端 2:终端
  21. OPERATEID int64 `json:"operateid" xorm:"'OPERATEID'"` // 最后操作人
  22. OPERATETIME string `json:"operatetime" xorm:"'OPERATETIME'"` // 最后操作时间
  23. ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  24. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构id
  25. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
  26. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
  27. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 现货商品单位id
  28. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  29. MODELNAME string `json:"modelname" xorm:"'MODELNAME'"` // 品类名称
  30. GMUNITID int32 `json:"gmunitid" xorm:"'GMUNITID'"` // 品类单位id
  31. OPERATORNAME string // 操作人名称
  32. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  33. GBENUMDICNAME string `json:"gbenumdicname"` // 品类单位名称
  34. }
  35. func (r *ErmcpSpotGoodsPrice) calc() {
  36. if r.OPERATESRC == 1 {
  37. r.OPERATORNAME = mtpcache.GetSystemmangerLoginCode(r.OPERATEID)
  38. } else {
  39. r.OPERATORNAME = mtpcache.GetUserNameByLoginId(r.OPERATEID)
  40. }
  41. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  42. r.GBENUMDICNAME = mtpcache.GetEnumDicitemName(r.GMUNITID)
  43. }
  44. func (r *ErmcpSpotGoodsPrice) buildSql() string {
  45. var sqlId utils.SQLVal = "SELECT t.WRSTANDARDID," +
  46. " t.SPOTGOODSMODELID," +
  47. " t.SPOTGOODSBRANDID," +
  48. " t.CURRENCYID," +
  49. " t.SPOTGOODSPRICE," +
  50. " t.TRADEDATE," +
  51. " t.OPERATESRC," +
  52. " t.OPERATEID," +
  53. " to_char(t.OPERATETIME, 'yyyy-mm-dd hh24:mi:ss') OPERATETIME," +
  54. " t.ISVALID," +
  55. " w.areauserid," +
  56. " w.wrstandardcode," +
  57. " w.wrstandardname," +
  58. " w.unitid," +
  59. " gb.brandname," +
  60. " gm.modelname," +
  61. " gm.unitid gmunitid" +
  62. " FROM ERMCP_SPOTGOODSPRICE t" +
  63. " left join wrstandard w" +
  64. " on t.wrstandardid = w.wrstandardid" +
  65. " left join spotgoodsbrand gb" +
  66. " on t.spotgoodsbrandid = gb.brandid" +
  67. " left join spotgoodsmodel gm" +
  68. " on t.spotgoodsmodelid = gm.modelid" +
  69. " WHERE 1 = 1"
  70. sqlId.And("w.areauserid", r.AREAUSERID)
  71. return sqlId.String()
  72. }
  73. // GetDataEx 获取现货市价
  74. func (r *ErmcpSpotGoodsPrice) GetDataEx() (interface{}, error) {
  75. sData := make([]ErmcpSpotGoodsPrice, 0)
  76. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  77. if err == nil {
  78. for i := range sData {
  79. sData[i].calc()
  80. }
  81. }
  82. return sData, err
  83. }
  84. // ErmcpSpotGoodsPriceLog 现货市价操作日志
  85. type ErmcpSpotGoodsPriceLog struct {
  86. LOGID int64 `json:"logid" xorm:"'LOGID'"` // 日志id
  87. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
  88. SPOTGOODSMODELID int32 `json:"spotgoodsmodelid" xorm:"'SPOTGOODSMODELID'"` // 现货品类ID(通用则为0)
  89. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID(通用则为0, 不为0则须先有品类ID)
  90. CURRENCYID int64 `json:"currencyid" xorm:"'CURRENCYID'"` // 报价货币ID
  91. SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"'SPOTGOODSPRICE'"` // 现货价格
  92. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  93. OPERATESRC int32 `json:"operatesrc" xorm:"'OPERATESRC'"` // 最后操作来源 - 1:管理端 2:终端
  94. OPERATEID int64 `json:"operateid" xorm:"'OPERATEID'"` // 最后操作人
  95. OPERATETIME string `json:"operatetime" xorm:"'OPERATETIME'"` // 最后操作时间
  96. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构id
  97. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
  98. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
  99. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 现货商品单位id
  100. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  101. MODELNAME string `json:"modelname" xorm:"'MODELNAME'"` // 品类名称
  102. GMUNITID int32 `json:"gmunitid" xorm:"'GMUNITID'"` // 品类单位id
  103. OPERATORNAME string // 操作人名称
  104. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  105. GBENUMDICNAME string `json:"gbenumdicname"` // 品类单位名称
  106. }
  107. func (r *ErmcpSpotGoodsPriceLog) calc() {
  108. if r.OPERATESRC == 1 {
  109. r.OPERATORNAME = mtpcache.GetSystemmangerLoginCode(r.OPERATEID)
  110. } else {
  111. r.OPERATORNAME = mtpcache.GetUserNameByLoginId(r.OPERATEID)
  112. }
  113. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  114. r.GBENUMDICNAME = mtpcache.GetEnumDicitemName(r.GMUNITID)
  115. }
  116. func (r *ErmcpSpotGoodsPriceLog) buildSql() string {
  117. var sqlId utils.SQLVal = "SELECT t.WRSTANDARDID," +
  118. " t.SPOTGOODSMODELID," +
  119. " t.SPOTGOODSBRANDID," +
  120. " t.CURRENCYID," +
  121. " t.SPOTGOODSPRICE," +
  122. " t.TRADEDATE," +
  123. " t.OPERATESRC," +
  124. " t.OPERATEID," +
  125. " to_char(t.OPERATETIME, 'yyyy-mm-dd hh24:mi:ss') OPERATETIME," +
  126. " t.LOGID," +
  127. " w.areauserid," +
  128. " w.wrstandardcode," +
  129. " w.wrstandardname," +
  130. " w.unitid," +
  131. " gb.brandname," +
  132. " gm.modelname," +
  133. " gm.unitid gmunitid" +
  134. " FROM ERMCP_SPOTGOODSPRICELOG t" +
  135. " left join wrstandard w" +
  136. " on t.wrstandardid = w.wrstandardid" +
  137. " left join spotgoodsbrand gb" +
  138. " on t.spotgoodsbrandid = gb.brandid" +
  139. " left join spotgoodsmodel gm" +
  140. " on t.spotgoodsmodelid = gm.modelid" +
  141. " WHERE 1 = 1"
  142. sqlId.And("w.areauserid", r.AREAUSERID)
  143. sqlId.And("t.wrstandardid", r.WRSTANDARDID)
  144. return sqlId.String()
  145. }
  146. // GetDataEx 获取现货市价信息日志
  147. func (r *ErmcpSpotGoodsPriceLog) GetDataEx() (interface{}, error) {
  148. sData := make([]ErmcpSpotGoodsPrice, 0)
  149. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  150. if err == nil {
  151. for i := range sData {
  152. sData[i].calc()
  153. }
  154. }
  155. return sData, err
  156. }