Просмотр исходного кода

数据库代码调整到models中

zhou.yingan 5 лет назад
Родитель
Сommit
588de480f8
2 измененных файлов с 38 добавлено и 32 удалено
  1. 2 32
      controllers/erms3/spotContract.go
  2. 36 0
      models/erms3.go

+ 2 - 32
controllers/erms3/spotContract.go

@@ -4,7 +4,6 @@ import (
 	"encoding/hex"
 	"encoding/json"
 	"math"
-	"mtp2_if/db"
 	"mtp2_if/global/app"
 	"mtp2_if/global/e"
 	"mtp2_if/logger"
@@ -496,37 +495,8 @@ func QuerySpotContractDetail(c *gin.Context) {
 	}
 
 	// 查询数据.
-	type spotContractDetail struct {
-		models.Erms3Spotcontractdetail `xorm:"extends"`
-		Areauserid                     int64     `json:"areauserid" xorm:"AREAUSERID"`                  // 所属机构
-		Accountid                      int64     `json:"accountid" xorm:"ACCOUNTID"`                    // 资金账户ID
-		Customeruserid                 int64     `json:"customeruserid" xorm:"CUSTOMERUSERID"`          // 客户ID
-		Customeraccountid              int64     `json:"customeraccountid" xorm:"CUSTOMERACCOUNTID"`    // 客户资金账户ID
-		Signdate                       time.Time `json:"signdate" xorm:"SIGNDATE"`                      // 签订日期
-		Closestatus                    int32     `json:"closestatus" xorm:"CLOSESTATUS"`                // 完结状态 - 0:未完结 1:已完结
-		Relatedbizid                   string    `json:"relatedbizid" xorm:"RELATEDBIZID"`              // 关联业务ID
-		Goodunit                       string    `json:"goodunit" xorm:"'GOODUNIT'"`                    // 报价单位
-		Wrstandardcode                 string    `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`       // 仓单标准代码
-		Wrstandardname                 string    `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`       // 仓单标准名称
-		Deliverygoodscode              string    `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"` // 交割商品代码
-		Deliverygoodsname              string    `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"` // 交割商品名称
-	}
-
-	datas := make([]spotContractDetail, 0)
-	engine := db.GetEngine()
-	s := engine.Table("ERMS3_SPOTCONTRACTDETAIL").
-		Join("LEFT", "ERMS3_SPOTCONTRACT", "ERMS3_SPOTCONTRACTDETAIL.SPOTCONTRACTID = ERMS3_SPOTCONTRACT.SPOTCONTRACTID").
-		Join("LEFT", "ERMS3_BIZTRADEDETAIL", "ERMS3_BIZTRADEDETAIL.SPOTDETAILID = ERMS3_SPOTCONTRACTDETAIL.SPOTDETAILID").
-		Join("LEFT", "WRSTANDARD", "WRSTANDARD.WRSTANDARDID = ERMS3_SPOTCONTRACTDETAIL.WRSTANDARDID").
-		Join("LEFT", "DELIVERYGOODS", "DELIVERYGOODS.DELIVERYGOODSID = WRSTANDARD.DELIVERYGOODSID").
-		Join("LEFT", "ENUMDICITEM", "WRSTANDARD.UNITID = ENUMDICITEM.ENUMITEMNAME AND ENUMDICITEM.ENUMDICCODE = 'goodsunit'").
-		Select(`to_char(ERMS3_SPOTCONTRACTDETAIL.SPOTCONTRACTID) SPOTCONTRACTID, ERMS3_SPOTCONTRACT.AREAUSERID, ERMS3_SPOTCONTRACT.ACCOUNTID, ERMS3_SPOTCONTRACT.CUSTOMERUSERID, 
-ERMS3_SPOTCONTRACT.CUSTOMERACCOUNTID, ERMS3_SPOTCONTRACT.CLOSESTATUS, ERMS3_SPOTCONTRACT.SIGNDATE, ERMS3_SPOTCONTRACTDETAIL.*, WRSTANDARD.WRSTANDARDNAME, WRSTANDARD.WRSTANDARDCODE, DELIVERYGOODS.DELIVERYGOODSNAME, DELIVERYGOODS.DELIVERYGOODSCODE, 
-to_char(ERMS3_BIZTRADEDETAIL.RELATEDBIZID) RELATEDBIZID, ENUMDICITEM.ENUMDICNAME GOODUNIT`).
-		Where("ERMS3_SPOTCONTRACT.CONTRACTTYPE = ? AND ERMS3_SPOTCONTRACT.CONTRACTMODE = ? AND ERMS3_SPOTCONTRACT.CLOSESTATUS = ?", req.ContractType, req.ContractMode, req.Status).
-		In("ERMS3_SPOTCONTRACT.ACCOUNTID", accountids).
-		Desc("ERMS3_SPOTCONTRACTDETAIL.SPOTCONTRACTID")
-	if err := s.Find(&datas); err != nil {
+	datas, err := models.QueryErms3SpotContractInfo(accountids, req.ContractType, req.ContractMode, req.Status)
+	if err != nil {
 		// 查询失败
 		logger.GetLogger().Errorf("QuerySpotContract failed: %s", err.Error())
 		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)

+ 36 - 0
models/erms3.go

@@ -52,6 +52,23 @@ func (Erms3Spotcontractdetail) TableName() string {
 	return "ERMS3_SPOTCONTRACTDETAIL"
 }
 
+// Erms3SpotContractInfo 合同明细.
+type Erms3SpotContractInfo struct {
+	Erms3Spotcontractdetail `xorm:"extends"`
+	Areauserid                     int64     `json:"areauserid" xorm:"AREAUSERID"`                  // 所属机构
+	Accountid                      int64     `json:"accountid" xorm:"ACCOUNTID"`                    // 资金账户ID
+	Customeruserid                 int64     `json:"customeruserid" xorm:"CUSTOMERUSERID"`          // 客户ID
+	Customeraccountid              int64     `json:"customeraccountid" xorm:"CUSTOMERACCOUNTID"`    // 客户资金账户ID
+	Signdate                       time.Time `json:"signdate" xorm:"SIGNDATE"`                      // 签订日期
+	Closestatus                    int32     `json:"closestatus" xorm:"CLOSESTATUS"`                // 完结状态 - 0:未完结 1:已完结
+	Relatedbizid                   string    `json:"relatedbizid" xorm:"RELATEDBIZID"`              // 关联业务ID
+	Goodunit                       string    `json:"goodunit" xorm:"'GOODUNIT'"`                    // 报价单位
+	Wrstandardcode                 string    `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`       // 仓单标准代码
+	Wrstandardname                 string    `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`       // 仓单标准名称
+	Deliverygoodscode              string    `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"` // 交割商品代码
+	Deliverygoodsname              string    `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"` // 交割商品名称
+}
+
 // Erms3SpotContractApply 现货合同申请表
 type Erms3SpotContractApply struct {
 	SpotContractID     int64     `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'" binging:"required"` // 现货合同ID(345+Unix秒时间戳(10位)+xxxxxx)
@@ -152,3 +169,22 @@ func AddSpotContractApply(spotContractApply Erms3SpotContractApply) error {
 
 	return err
 }
+
+func QueryErms3SpotContractInfo(accountids []int64, contracttype, contractmode, status int32) ([]Erms3SpotContractInfo, error) {
+	datas := make([]Erms3SpotContractInfo, 0)
+	engine := db.GetEngine()
+	s := engine.Table("ERMS3_SPOTCONTRACTDETAIL").
+		Join("LEFT", "ERMS3_SPOTCONTRACT", "ERMS3_SPOTCONTRACTDETAIL.SPOTCONTRACTID = ERMS3_SPOTCONTRACT.SPOTCONTRACTID").
+		Join("LEFT", "ERMS3_BIZTRADEDETAIL", "ERMS3_BIZTRADEDETAIL.SPOTDETAILID = ERMS3_SPOTCONTRACTDETAIL.SPOTDETAILID").
+		Join("LEFT", "WRSTANDARD", "WRSTANDARD.WRSTANDARDID = ERMS3_SPOTCONTRACTDETAIL.WRSTANDARDID").
+		Join("LEFT", "DELIVERYGOODS", "DELIVERYGOODS.DELIVERYGOODSID = WRSTANDARD.DELIVERYGOODSID").
+		Join("LEFT", "ENUMDICITEM", "WRSTANDARD.UNITID = ENUMDICITEM.ENUMITEMNAME AND ENUMDICITEM.ENUMDICCODE = 'goodsunit'").
+		Select(`to_char(ERMS3_SPOTCONTRACTDETAIL.SPOTCONTRACTID) SPOTCONTRACTID, ERMS3_SPOTCONTRACT.AREAUSERID, ERMS3_SPOTCONTRACT.ACCOUNTID, ERMS3_SPOTCONTRACT.CUSTOMERUSERID, 
+ERMS3_SPOTCONTRACT.CUSTOMERACCOUNTID, ERMS3_SPOTCONTRACT.CLOSESTATUS, ERMS3_SPOTCONTRACT.SIGNDATE, ERMS3_SPOTCONTRACTDETAIL.*, WRSTANDARD.WRSTANDARDNAME, WRSTANDARD.WRSTANDARDCODE, DELIVERYGOODS.DELIVERYGOODSNAME, DELIVERYGOODS.DELIVERYGOODSCODE, 
+to_char(ERMS3_BIZTRADEDETAIL.RELATEDBIZID) RELATEDBIZID, ENUMDICITEM.ENUMDICNAME GOODUNIT`).
+		Where("ERMS3_SPOTCONTRACT.CONTRACTTYPE = ? AND ERMS3_SPOTCONTRACT.CONTRACTMODE = ? AND ERMS3_SPOTCONTRACT.CLOSESTATUS = ?", contracttype, contractmode, status).
+		In("ERMS3_SPOTCONTRACT.ACCOUNTID", accountids).
+		Desc("ERMS3_SPOTCONTRACTDETAIL.SPOTCONTRACTID")
+	err := s.Find(&datas)
+	return datas, err
+}