ermcpWrstandard.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/1/13 11:16
  4. * @Modify : 2021/1/13 11:16
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/logger"
  11. )
  12. // 现货商品表
  13. type ErmcpWrstandard struct {
  14. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID(SEQ_WRSTANDARD)
  15. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
  16. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种ID
  17. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位ID
  18. MINIVALUE int32 `json:"minivalue" xorm:"'MINIVALUE'"` // 最小变动值
  19. MINIVALUEDP int32 `json:"minivaluedp" xorm:"'MINIVALUEDP'"` // 最小变动值小数位
  20. REALMINIVALUE int32 `json:"realminivalue" xorm:"'REALMINIVALUE'"` // 实际最小变动值
  21. REALMINIVALUEDP int32 `json:"realminivaluedp" xorm:"'REALMINIVALUEDP'"` // 实际最小变动值小数位
  22. CREATORID int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  23. CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  24. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
  25. AREAUSERID int `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  26. EnumdicName string `json:"enumdicname"` // 单位名称
  27. ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 0-无效(停用) 1-有效(正常)
  28. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  29. REMARK string `json:"remark" xorm:"'REMARK'"` // 备注
  30. }
  31. func (r *ErmcpWrstandard) buildSql() string {
  32. str := "select WRSTANDARDID," +
  33. " WRSTANDARDCODE," +
  34. " DELIVERYGOODSID," +
  35. " UNITID," +
  36. " MINIVALUE," +
  37. " MINIVALUEDP," +
  38. " REALMINIVALUE," +
  39. " REALMINIVALUEDP," +
  40. " CREATORID," +
  41. " to_char(CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  42. " WRSTANDARDNAME," +
  43. " ISVALID," +
  44. " to_char(UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
  45. " REMARK," +
  46. " AREAUSERID" +
  47. " from wrstandard t" +
  48. " where t.AREAUSERID=%v"
  49. sqlId := fmt.Sprintf(str, r.AREAUSERID)
  50. if r.WRSTANDARDID > 0 {
  51. sqlId = sqlId + fmt.Sprintf(" and WRSTANDARDID=%v", r.WRSTANDARDID)
  52. }
  53. return sqlId
  54. }
  55. // 查询现货商品
  56. func (r *ErmcpWrstandard) GetData() ([]ErmcpWrstandard, error) {
  57. sData := make([]ErmcpWrstandard, 0)
  58. e := db.GetEngine()
  59. if err := e.SQL(r.buildSql()).Find(&sData); err != nil {
  60. logger.GetLogger().Errorf("query wrstardard fail, %v", err)
  61. return sData, err
  62. }
  63. return sData, nil
  64. }
  65. // 商品型号表
  66. type GoodsTypeModel struct {
  67. MODELID int `json:"modelid" xorm:"'MODELID'"` // 型号ID
  68. MODELNAME string `json:"modelname" xorm:"'MODELNAME'"` // 型号名称
  69. WRSTANDARDID int64 `json:"-" xorm:"'WRSTANDARDID'"` // 现货商品ID
  70. DELIVERYGOODSID int32 `json:"-" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
  71. AREAUSERID int `json:"-" xorm:"'AREAUSERID'"` // 所属机构
  72. ISVALID int32 `json:"-" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  73. CREATORSRC int32 `json:"-" xorm:"'CREATORSRC'"` // 创建人来源 - 1:管理端 2:终端
  74. CREATORID int32 `json:"-" xorm:"'CREATORID'"` // 创建人
  75. CREATETIME string `json:"-" xorm:"'CREATETIME'"` // SYSDATE 创建时间
  76. UPDATORSRC int32 `json:"-" xorm:"'UPDATORSRC'"` // 更新人来源 - 1:管理端 2:终端
  77. UPDATORID int32 `json:"-" xorm:"'UPDATORID'"` // 更新人
  78. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  79. }
  80. // 获取商品型号表数据
  81. func (r *GoodsTypeModel) GetData() ([]GoodsTypeModel, error) {
  82. sData := make([]GoodsTypeModel, 0)
  83. if err := db.GetEngine().SQL(r.buildSql()).Find(&sData); err != nil {
  84. logger.GetLogger().Errorf("query goodsTypeModel fail, %v", err)
  85. return nil, err
  86. }
  87. return sData, nil
  88. }
  89. func (r *GoodsTypeModel) buildSql() string {
  90. sqlId := "select MODELID," +
  91. " MODELNAME," +
  92. " WRSTANDARDID," +
  93. " DELIVERYGOODSID," +
  94. " AREAUSERID," +
  95. " ISVALID," +
  96. " CREATORSRC," +
  97. " CREATORID," +
  98. " to_char(CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  99. " UPDATORSRC," +
  100. " UPDATORID," +
  101. " to_char(UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME" +
  102. " from spotgoodsmodel where ISVALID=1"
  103. if r.AREAUSERID > 0 {
  104. sqlId = sqlId + fmt.Sprintf(" and AREAUSERID=%v", r.AREAUSERID)
  105. }
  106. if r.WRSTANDARDID > 0 {
  107. sqlId = sqlId + fmt.Sprintf(" and WRSTANDARDID=%v", r.WRSTANDARDID)
  108. }
  109. return sqlId
  110. }
  111. // 商品品牌
  112. type GoodsBrand struct {
  113. BRANDID int `json:"brandid" xorm:"'bRANDID'"` // 品牌ID
  114. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  115. WRSTANDARDID int64 `json:"-" xorm:"'WRSTANDARDID'"` // 现货商品ID
  116. DELIVERYGOODSID int32 `json:"-" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
  117. AREAUSERID int `json:"-" xorm:"'AREAUSERID'"` // 所属机构
  118. ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  119. }
  120. func (r *GoodsBrand) buildSql() string {
  121. sqlId := "select BRANDID," +
  122. " BRANDNAME," +
  123. " WRSTANDARDID," +
  124. " DELIVERYGOODSID," +
  125. " AREAUSERID," +
  126. " ISVALID" +
  127. " from spotgoodsbrand" +
  128. " where ISVALID = 1"
  129. if r.AREAUSERID > 0 {
  130. sqlId = sqlId + fmt.Sprintf(" and AREAUSERID=%v", r.AREAUSERID)
  131. }
  132. if r.WRSTANDARDID > 0 {
  133. sqlId = sqlId + fmt.Sprintf(" and WRSTANDARDID=%v", r.WRSTANDARDID)
  134. }
  135. return sqlId
  136. }
  137. // 获取品牌数据
  138. func (r *GoodsBrand) GetData() ([]GoodsBrand, error) {
  139. sData := make([]GoodsBrand, 0)
  140. if err := db.GetEngine().SQL(r.buildSql()).Find(&sData); err != nil {
  141. logger.GetLogger().Errorf("query GoodsBrand fail, %v", err)
  142. return nil, err
  143. }
  144. return sData, nil
  145. }
  146. // 现货商品折算配置明细表
  147. type WRSConverTDetail struct {
  148. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
  149. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
  150. MIDDLEGOODSID int64 `json:"middlegoodsid" xorm:"'MIDDLEGOODSID'"` // 套保品种ID
  151. CONVERTRATIO float64 `json:"convertratio" xorm:"'CONVERTRATIO'"` // 套保系数
  152. MODIFYTIME string `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  153. MIDDLEGOODSNAME string `json:"middlegoodsname" xorm:"'middlegoodsname'"` // 套保品种名称
  154. MIDDLEGOODSCODE string `json:"middlegoodscode" xorm:"'middlegoodscode'"` // 套保品种代码
  155. }
  156. func (r *WRSConverTDetail) buildSql() string {
  157. sqlId := "select t.WRSTANDARDID," +
  158. " t.DELIVERYGOODSID," +
  159. " t.MIDDLEGOODSID," +
  160. " t.CONVERTRATIO," +
  161. " to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
  162. " m.middlegoodsname," +
  163. " m.middlegoodscode" +
  164. " from Erms2_Wrsconvertdetail t" +
  165. " left join erms_middlegoods m" +
  166. " on t.middlegoodsid = m.middlegoodsid" +
  167. " where 1=1"
  168. if r.WRSTANDARDID > 0 {
  169. sqlId = sqlId + fmt.Sprintf(" and t.wrstandardid=%v", r.WRSTANDARDID)
  170. }
  171. return sqlId
  172. }
  173. // 获取现货商品折算配置明细表数据
  174. func (r *WRSConverTDetail) GetData() ([]WRSConverTDetail, error) {
  175. sData := make([]WRSConverTDetail, 0)
  176. if err := db.GetEngine().SQL(r.buildSql()).Find(&sData); err != nil {
  177. logger.GetLogger().Errorf("query WRSConverTDetail fail, %v", err)
  178. return nil, err
  179. }
  180. return sData, nil
  181. }
  182. // 现货商品详细
  183. type ErmcpWrstandDetail struct {
  184. Wrd ErmcpWrstandard `json:"wrd"` // 基本信息
  185. GtList []GoodsTypeModel `json:"gtList"` // 型号列表
  186. GbList []GoodsBrand `json:"gbList"` // 品牌列表
  187. WrsList []WRSConverTDetail `json:"wrsList"` // 套保信息列表
  188. }
  189. // 查询现货商品详细
  190. func (r *ErmcpWrstandDetail) GetData() (ErmcpWrstandDetail, error) {
  191. // 获取基本信息
  192. m := ErmcpWrstandard{AREAUSERID: r.Wrd.AREAUSERID, WRSTANDARDID: r.Wrd.WRSTANDARDID}
  193. d, err := m.GetData()
  194. if err != nil {
  195. return ErmcpWrstandDetail{}, err
  196. }
  197. if d == nil || len(d) == 0 {
  198. return ErmcpWrstandDetail{}, fmt.Errorf("no record")
  199. }
  200. rsp := ErmcpWrstandDetail{}
  201. rsp.Wrd = d[0]
  202. // 获取型号信息
  203. gt := GoodsTypeModel{AREAUSERID: rsp.Wrd.AREAUSERID, WRSTANDARDID: rsp.Wrd.WRSTANDARDID}
  204. if val, err := gt.GetData(); err == nil {
  205. rsp.GtList = val
  206. }
  207. // 获取品牌信息
  208. gb := GoodsBrand{AREAUSERID: rsp.Wrd.AREAUSERID, WRSTANDARDID: rsp.Wrd.WRSTANDARDID}
  209. if val, err := gb.GetData(); err == nil {
  210. rsp.GbList = val
  211. }
  212. // 获取套保信息
  213. wrs := WRSConverTDetail{WRSTANDARDID: rsp.Wrd.WRSTANDARDID}
  214. if val, err := wrs.GetData(); err == nil {
  215. rsp.WrsList = val
  216. }
  217. return rsp, nil
  218. }