zwl 5 yıl önce
ebeveyn
işleme
11a9502420
2 değiştirilmiş dosya ile 122 ekleme ve 88 silme
  1. 27 64
      controllers/erms3/spotContract.go
  2. 95 24
      models/erms3.go

+ 27 - 64
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"
@@ -147,80 +146,44 @@ func AddSpotContractApply(c *gin.Context) {
 		return
 	}
 
-	// 组织sql,插入现货合同申请信息
-	sql := `INSERT INTO ERMS3_SPOTCONTRACTAPPLY(SPOTCONTRACTID,
-				TRADEDATE,
-				CONTRACTNO,
-				CONTRACTTYPE,
-				AREAUSERID,
-				ACCOUNTID,
-				CUSTOMERUSERID,
-				CUSTOMERACCOUNTID,
-				SIGNDATE,
-				LASTDATE,
-				CONTRACTATTACHMENT,
-				ORIMARGINPAYER,
-				ORIMARGIN,
-				REMARK,
-				DETAILJSON,
-				APPLYSTATUS,
-				APPLYSRC,
-				MARKETID,
-				CREATORID,
-				CREATETIME)
-			VALUES(
-				?,
-				?,
-				?,
-				?,
-				?,
-				?,
-				?,
-				?,
-				to_date(?, 'YYYY-MM-DD HH24:MI:SS'),
-				to_date(?, 'YYYY-MM-DD HH24:MI:SS'),
-				?,
-				?,
-				?,
-				?,
-				?,
-				0,
-				2,
-				?,
-				?,
-				sysdate)`
-
-	engine := db.GetEngine()
-	if _, err := engine.Exec(sql,
-		spotcontractid,
-		tradedate,
-		req.ContractNo,
-		req.ContractType,
-		req.AreaUserID,
-		req.AccountID,
-		req.CustomerUserID,
-		req.CustomerAccountID,
-		req.SignDate,
-		req.LastDate,
-		req.ContractAttachment,
-		req.OriMarginPayer,
-		req.OriMargin,
-		req.Remark,
-		detailjson,
-		req.MarketID,
-		req.CreatorID); err != nil {
+	// 组建现货合同申请内容
+	spotContractApply := models.Erms3SpotContractApply{
+		SpotContractID:     spotcontractid,
+		TradeDate:          tradedate,
+		ContractNo:         req.ContractNo,
+		ContractType:       req.ContractType,
+		AreaUserID:         req.AreaUserID,
+		AccountID:          req.AccountID,
+		CustomerUserID:     req.CustomerUserID,
+		CustomerAccountID:  req.CustomerAccountID,
+		SignDate:           req.SignDate,
+		LastDate:           req.LastDate,
+		ContractAttachment: req.ContractAttachment,
+		OriMarginPayer:     req.OriMarginPayer,
+		OriMargin:          req.OriMargin,
+		Remark:             req.Remark,
+		DetailJSON:         detailjson,
+		ApplyStatus:        0,
+		ApplySrc:           2,
+		MarketID:           req.MarketID,
+		CreatorID:          req.CreatorID,
+	}
+
+	// 调用接口,插入现货合同申请信息
+	if err := models.AddSpotContractApply(spotContractApply); err != nil {
 		// 插入失败
 		logger.GetLogger().Errorf("AddSpotContractApply failed: %s", err.Error())
 		appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
 		return
 	}
 
+	// 组织响应信息
 	rsp := AddSpotContractApplyRsp{
 		SpotContractID: spotcontractid,
 		ContractNo:     req.ContractNo,
 	}
 
-	// 查询成功
+	// 插入成功
 	logger.GetLogger().Debugln("AddSpotContractApply successed: %v", rsp)
 	appG.Response(http.StatusOK, e.SUCCESS, rsp)
 }

+ 95 - 24
models/erms3.go

@@ -1,33 +1,36 @@
 // Package models 211.3 风险管理系统2020_现货合同
 package models
 
-import "time"
+import (
+	"mtp2_if/db"
+	"time"
+)
 
 // Erms3SpotContractApply 现货合同申请表
 type Erms3SpotContractApply struct {
-	SpotContractID           int64     `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'" binging:"required"`  // 现货合同ID(345+Unix秒时间戳(10位)+xxxxxx)
-	TradeDate                string    `json:"tradedate"  xorm:"'TRADEDATE'"`                               // 交易日(yyyyMMdd)
-	ContractNo               string    `json:"contractno"  xorm:"'CONTRACTNO'"`                             // 现货合同编号
-	ContractType             int32     `json:"contracttype"  xorm:"'CONTRACTTYPE'"`                         // 现货合同类型 - 1:采购 -1:销售
-	AreaUserID               int32     `json:"areauserid"  xorm:"'AREAUSERID'"`                             // 所属机构
-	AccountID                int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                               // 资金账户ID
-	CustomerUserID           int32     `json:"customeruserid"  xorm:"'CUSTOMERUSERID'"`                     // 客户ID
-	CustomerAccountID        int64     `json:"customeraccountid"  xorm:"'CUSTOMERACCOUNTID'"`               // 客户资金账户ID
-	SignDate                 time.Time `json:"signdate"  xorm:"'SIGNDATE'"`                                 // 签订日期
-	LastDate                 time.Time `json:"lastdate"  xorm:"'LASTDATE'"`                                 // 交货时间
-	ContractAttachment       string    `json:"contractattachment"  xorm:"'CONTRACTATTACHMENT'"`             // 合同附件
-	OriMarginPayer           int32     `json:"orimarginpayer"  xorm:"'ORIMARGINPAYER'"`                     // 初始保证金支付方 -1:买方 2:卖方
-	OriMargin                float64   `json:"orimargin"  xorm:"'ORIMARGIN'"`                               // 初始保证金
-	Remark                   string    `json:"remark"  xorm:"'REMARK'"`                                     // 备注
-	DetailJSON               string    `json:"detailjson"  xorm:"'DETAILJSON'"`                             // 明细JSON
-	ApplyStatus              int32     `json:"applystatus"  xorm:"'APPLYSTATUS'"`                           // 申请状态 - 0:未审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝
-	ApplySrc                 int32     `json:"applysrc"  xorm:"'APPLYSRC'"`                                 // 申请来源 - 1:管理端 2:终端
-	MarketID                 int32     `json:"marketid"  xorm:"'MARKETID'"`                                 // 市场ID
-	CreatorID                int32     `json:"creatorid"  xorm:"'CREATORID'"`                               // 申请人
-	CreateTime               time.Time `json:"createtime"  xorm:"'CREATETIME'"`                             // 申请时间
-	AuditID                  int32     `json:"auditid"  xorm:"'AUDITID'"`                                   // 审核人
-	AuditTime                time.Time `json:"audittime"  xorm:"'AUDITTIME'"`                               // 审核时间
-	AuditRemark              string    `json:"auditremark"  xorm:"'AUDITREMARK'"`                           //审核备注
+	SpotContractID     int64     `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'" binging:"required"` // 现货合同ID(345+Unix秒时间戳(10位)+xxxxxx)
+	TradeDate          string    `json:"tradedate"  xorm:"'TRADEDATE'"`                              // 交易日(yyyyMMdd)
+	ContractNo         string    `json:"contractno"  xorm:"'CONTRACTNO'"`                            // 现货合同编号
+	ContractType       int32     `json:"contracttype"  xorm:"'CONTRACTTYPE'"`                        // 现货合同类型 - 1:采购 -1:销售
+	AreaUserID         int32     `json:"areauserid"  xorm:"'AREAUSERID'"`                            // 所属机构
+	AccountID          int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                              // 资金账户ID
+	CustomerUserID     int32     `json:"customeruserid"  xorm:"'CUSTOMERUSERID'"`                    // 客户ID
+	CustomerAccountID  int64     `json:"customeraccountid"  xorm:"'CUSTOMERACCOUNTID'"`              // 客户资金账户ID
+	SignDate           time.Time `json:"signdate"  xorm:"'SIGNDATE'"`                                // 签订日期
+	LastDate           time.Time `json:"lastdate"  xorm:"'LASTDATE'"`                                // 交货时间
+	ContractAttachment string    `json:"contractattachment"  xorm:"'CONTRACTATTACHMENT'"`            // 合同附件
+	OriMarginPayer     int32     `json:"orimarginpayer"  xorm:"'ORIMARGINPAYER'"`                    // 初始保证金支付方 -1:买方 2:卖方
+	OriMargin          float64   `json:"orimargin"  xorm:"'ORIMARGIN'"`                              // 初始保证金
+	Remark             string    `json:"remark"  xorm:"'REMARK'"`                                    // 备注
+	DetailJSON         string    `json:"detailjson"  xorm:"'DETAILJSON'"`                            // 明细JSON
+	ApplyStatus        int32     `json:"applystatus"  xorm:"'APPLYSTATUS'"`                          // 申请状态 - 0:未审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝
+	ApplySrc           int32     `json:"applysrc"  xorm:"'APPLYSRC'"`                                // 申请来源 - 1:管理端 2:终端
+	MarketID           int32     `json:"marketid"  xorm:"'MARKETID'"`                                // 市场ID
+	CreatorID          int32     `json:"creatorid"  xorm:"'CREATORID'"`                              // 申请人
+	CreateTime         time.Time `json:"createtime"  xorm:"'CREATETIME'"`                            // 申请时间
+	AuditID            int32     `json:"auditid"  xorm:"'AUDITID'"`                                  // 审核人
+	AuditTime          time.Time `json:"audittime"  xorm:"'AUDITTIME'"`                              // 审核时间
+	AuditRemark        string    `json:"auditremark"  xorm:"'AUDITREMARK'"`                          // 审核备注
 }
 
 // TableName is ERMS3_SPOTCONTRACTAPPLY
@@ -35,3 +38,71 @@ func (Erms3SpotContractApply) TableName() string {
 	return "ERMS3_SPOTCONTRACTAPPLY"
 }
 
+// AddSpotContractApply 插入现货合同记录
+func AddSpotContractApply(spotContractApply Erms3SpotContractApply) error {
+	engine := db.GetEngine()
+
+	// 组织sql,插入现货合同申请信息
+	sql := `INSERT INTO ERMS3_SPOTCONTRACTAPPLY(SPOTCONTRACTID,
+			  TRADEDATE,
+			  CONTRACTNO,
+			  CONTRACTTYPE,
+			  AREAUSERID,
+			  ACCOUNTID,
+			  CUSTOMERUSERID,
+			  CUSTOMERACCOUNTID,
+			  SIGNDATE,
+			  LASTDATE,
+			  CONTRACTATTACHMENT,
+			  ORIMARGINPAYER,
+			  ORIMARGIN,
+			  REMARK,
+			  DETAILJSON,
+			  APPLYSTATUS,
+			  APPLYSRC,
+			  MARKETID,
+			  CREATORID,
+			  CREATETIME)
+			VALUES(?,
+				?,
+				?,
+				?,
+				?,
+				?,
+				?,
+				?,
+				to_date(?, 'YYYY-MM-DD HH24:MI:SS'),
+				to_date(?, 'YYYY-MM-DD HH24:MI:SS'),
+				?,
+				?,
+				?,
+				?,
+				?,
+				0,
+				2,
+				?,
+				?,
+				sysdate)`
+	_, err := engine.Exec(sql,
+		spotContractApply.SpotContractID,
+		spotContractApply.TradeDate,
+		spotContractApply.ContractNo,
+		spotContractApply.ContractType,
+		spotContractApply.AreaUserID,
+		spotContractApply.AccountID,
+		spotContractApply.CustomerUserID,
+		spotContractApply.CustomerAccountID,
+		spotContractApply.SignDate,
+		spotContractApply.LastDate,
+		spotContractApply.ContractAttachment,
+		spotContractApply.OriMarginPayer,
+		spotContractApply.OriMargin,
+		spotContractApply.Remark,
+		spotContractApply.DetailJSON,
+		spotContractApply.ApplyStatus,
+		spotContractApply.ApplySrc,
+		spotContractApply.MarketID,
+		spotContractApply.CreatorID)
+
+	return err
+}