/**
* @Author: zou.yingbin
* @Create  : 2021/4/13 9:52
* @Modify  : 2021/4/13 9:52
 */

package models

import (
	"mtp2_if/db"
	"mtp2_if/utils"
)

// ErmcpFuturesCompany 期货公司
type ErmcpFuturesCompany struct {
	MHPADDRESS       string `json:"mhpaddress"  xorm:"'MHPADDRESS'"`             // MHP服务地址(IP:Port)
	FCID             int32  `json:"fcid"  xorm:"'FCID'"`                         // 期货公司ID(SEQ_ERMCP_FUTURESCOMPANY)
	FCNAME           string `json:"fcname"  xorm:"'FCNAME'"`                     // 期货公司名称
	CHANNELID        string `json:"channelid"  xorm:"'CHANNELID'"`               // 对冲渠道ID
	BROKERID         string `json:"brokerid"  xorm:"'BROKERID'"`                 // 经纪公司代码
	CHANNELADDRESS   string `json:"channeladdress"  xorm:"'CHANNELADDRESS'"`     // 对冲渠道服务地址(多个地址用逗号分隔) -- 192.168.30.10:3000,192.168.30.10:3001
	RISKRULEGROUPID  string `json:"riskrulegroupid"  xorm:"'RISKRULEGROUPID'"`   // 风控规则组ID
	TRADEMARGINTMPID string `json:"trademargintmpid"  xorm:"'TRADEMARGINTMPID'"` // 保证金模板ID [TradeConfigTmpType为1]
	TRADEFEETMPID    string `json:"tradefeetmpid"  xorm:"'TRADEFEETMPID'"`       // 手续费模板ID[TradeConfigTmpType为2]
	TRADERATETMPID   string `json:"traderatetmpid"  xorm:"'TRADERATETMPID'"`     // 汇率模板ID[TradeConfigTmpType为3]
	CREATORID        string `json:"creatorid"  xorm:"'CREATORID'"`               // 创建人
	CREATETIME       string `json:"createtime"  xorm:"'CREATETIME'"`             // 创建时间
	UPDATORID        string `json:"updatorid"  xorm:"'UPDATORID'"`               // 更新人
	UPDATETIME       string `json:"updatetime"  xorm:"'UPDATETIME'"`             // 更新时间
	ISVALID          int32  `json:"isvalid"  xorm:"'ISVALID'"`                   // 是否有效 - 0:无效 1:有效
}

func (r *ErmcpFuturesCompany) calc() {
}

func (r *ErmcpFuturesCompany) buildSql() string {
	var sqlId utils.SQLVal = "SELECT t.MHPADDRESS," +
		"       t.FCID," +
		"       t.FCNAME," +
		"       t.CHANNELID," +
		"       t.BROKERID," +
		"       t.CHANNELADDRESS," +
		"       t.RISKRULEGROUPID," +
		"       t.TRADEMARGINTMPID," +
		"       t.TRADEFEETMPID," +
		"       t.TRADERATETMPID," +
		"       t.CREATORID," +
		"       to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
		"       t.UPDATORID," +
		"       to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
		"       to_char(t.ISVALID) ISVALID" +
		"  FROM ERMCP_FUTURESCOMPANY t" +
		" WHERE t.isvalid=1"
	return sqlId.String()
}

// GetDataEx 获取期货公司
func (r *ErmcpFuturesCompany) GetDataEx() (interface{}, error) {
	sData := make([]ErmcpFuturesCompany, 0)
	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
	for i := range sData {
		sData[i].calc()
	}
	return sData, err
}
