ermcpGGConvertconfig.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/1/27 9:50
  4. * @Modify : 2021/1/27 9:50
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/mtpcache"
  11. )
  12. // 期货品种系数表
  13. type ErmcpGGConvertCfg struct {
  14. Srcgoodsgroupid int32 `json:"srcgoodsgroupid" xorm:"'Srcgoodsgroupid'"` // 源品种ID
  15. Destgoodsgroupid int32 `json:"destgoodsgroupid" xorm:"'Destgoodsgroupid'"` // 目标品种ID
  16. Convertratio float64 `json:"convertratio" xorm:"'Convertratio'"` // 折算系数
  17. SrcExchangeCode string `json:"srcexchangecode" xorm:"'SrcExchangeCode'"` // 源期货交易所
  18. SrcName string `json:"srcname" xorm:"'SrcName'"` // 源品种名称
  19. SrcCode string `json:"srccode" xorm:"'SrcCode'"` // 源品种代码
  20. SrcUnitid uint32 `json:"srcunitid" xorm:"'SrcUnitid'"` // 源品种单位ID
  21. SrcUnitidName string `json:"srcunitidname" xorm:"'-'"` // 源品种单位名称
  22. DstExchangeCode string `json:"dstexchangecode" xorm:"'DstExchangeCode'"` // 目标期货交易所
  23. DstName string `json:"dstname" xorm:"'DstName'"` // 目标品种名称
  24. DstCode string `json:"dstcode" xorm:"'DstCode'"` // 目录品种代码
  25. DstUnitid uint32 `json:"dstunitid" xorm:"'DstUnitid'"` // 目标品种单位ID
  26. DstUnitidName string `json:"dstunitidname"` // 目标品种单位名称
  27. MODIFYTIME string `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  28. }
  29. func (r *ErmcpGGConvertCfg) Calc() {
  30. r.SrcUnitidName = mtpcache.GetEnumDicitemName(int32(r.SrcUnitid))
  31. r.DstUnitidName = mtpcache.GetEnumDicitemName(int32(r.DstUnitid))
  32. }
  33. // 获取数据
  34. func (r *ErmcpGGConvertCfg) GetData() ([]interface{}, error) {
  35. sData := make([]ErmcpGGConvertCfg, 0)
  36. if err := db.GetEngine().SQL(r.buildSql()).Find(&sData); err != nil {
  37. return nil, err
  38. }
  39. iData := make([]interface{}, 0)
  40. for i := range sData {
  41. iData = append(iData, &sData[i])
  42. }
  43. return iData, nil
  44. }
  45. func (r *ErmcpGGConvertCfg) buildSql() string {
  46. sqlId := "select t.srcgoodsgroupid," +
  47. " t.destgoodsgroupid," +
  48. " t.convertratio," +
  49. " to_char(t.modifytime,'yyyy-mm-dd hh24:mi:ss') modifytime," +
  50. " ex1.exexchangecode srcExchangeCode," +
  51. " g1.goodsgroupname srcName," +
  52. " g1.outergroupcode srcCode," +
  53. " g1.goodunitid srcUnitid," +
  54. " ex2.exexchangecode dstExchangeCode," +
  55. " g2.goodsgroupname dstName," +
  56. " g2.outergroupcode dstCode," +
  57. " g2.goodunitid dstUnitid" +
  58. " from ERMCP_GGConvertconfig t" +
  59. " left join goodsgroup g1" +
  60. " on t.srcgoodsgroupid = g1.goodsgroupid" +
  61. " left join goodsgroup g2" +
  62. " on t.destgoodsgroupid = g2.goodsgroupid" +
  63. " left join externalexchange ex1" +
  64. " on g1.exexchangeid = ex1.autoid" +
  65. " left join externalexchange ex2" +
  66. " on g2.exexchangeid = ex2.autoid" +
  67. " where 1 = 1"
  68. if r.Destgoodsgroupid > 0 {
  69. sqlId = sqlId + fmt.Sprintf("and t.Destgoodsgroupid=%v", r.Destgoodsgroupid)
  70. }
  71. if r.Srcgoodsgroupid > 0 {
  72. sqlId = sqlId + fmt.Sprintf("and t.Srcgoodsgroupid=%v", r.Srcgoodsgroupid)
  73. }
  74. sqlId += " order by t.destgoodsgroupid, t.modifytime desc"
  75. return sqlId
  76. }
  77. // 可选择的源期货品种
  78. type ErmcpAvalidGoodsGroupModel struct {
  79. Goodsgroupid int32 `json:"goodsgroupid" xorm:"'Goodsgroupid'"` // 期货品种id
  80. Goodsgroupname string `json:"goodsgroupname" xorm:"'Goodsgroupname'"` // 期货品种名称
  81. Outergroupcode string `json:"outergroupcode" xorm:"'Outergroupcode'"` // 期货品种代码
  82. Goodunitid int32 `json:"goodunitid" xorm:"'Goodunitid'"` // 品种单位id
  83. GoodunitName string `json:"goodunitname" xorm:"'GoodunitName'"` // 品种单位名称
  84. AreaUserId int64 `json:"-"` // 所属机构id
  85. }
  86. // 获取数据
  87. func (r *ErmcpAvalidGoodsGroupModel) GetDataEx() (interface{}, error) {
  88. sData := make([]ErmcpAvalidGoodsGroupModel, 0)
  89. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  90. return sData, err
  91. }
  92. func (r *ErmcpAvalidGoodsGroupModel) buildSql() string {
  93. sqlId := "select distinct g.groupcategroyid," +
  94. " g.goodsgroupid," +
  95. " g.goodsgroupname," +
  96. " g.outergroupcode," +
  97. " g.goodunitid" +
  98. " from ERMCP_GGConvertconfig t" +
  99. " left join goodsgroup g" +
  100. " on t.srcgoodsgroupid = g.goodsgroupid" +
  101. " where g.groupcategroyid not in" +
  102. " (select g.groupcategroyid" +
  103. " from erms_middlegoods t" +
  104. " left join goodsgroup g" +
  105. " on t.goodsgroupid = g.goodsgroupid" +
  106. " where t.areauserid = %v" +
  107. " and t.goodsgroupid is not null)"
  108. sqlId = fmt.Sprintf(sqlId, r.AreaUserId)
  109. return sqlId
  110. }