// Package models 211.3 风险管理系统2020_现货合同 package models import ( "mtp2_if/db" "strconv" "strings" "time" ) // Erms3Spotcontractdetail 合同标的明细表 type Erms3Spotcontractdetail struct { Spotdetailid string `json:"spotdetailid" xorm:"SPOTDETAILID"` // 标的明细ID(346+Unix秒时间戳(10位)+xxxxxx) Spotcontractid string `json:"spotcontractid" xorm:"SPOTCONTRACTID"` // 现货合同ID Wrstandardid int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 仓单标准ID Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID Tradedate string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd) Contracttype int32 `json:"contracttype" xorm:"CONTRACTTYPE"` // 现货合同类型 - 1:采购 -1:销售 Accountid int64 `json:"accountid" xorm:"ACCOUNTID"` // 资金账户ID Customeraccountid int64 `json:"customeraccountid" xorm:"CUSTOMERACCOUNTID"` // 客户资金账户ID Producttype int32 `json:"producttype" xorm:"PRODUCTTYPE"` // 产品类型 - 1:标准仓单 2:等标 3:非标 Deliverygoodsdesc string `json:"deliverygoodsdesc" xorm:"DELIVERYGOODSDESC"` // 产品规格 - 根据此字段生成仓单标准、仓单要素类型 Warehouseid int64 `json:"warehouseid" xorm:"WAREHOUSEID"` // 仓库ID Pointdesc string `json:"pointdesc" xorm:"POINTDESC"` // 点价描述 Priceqty float64 `json:"priceqty" xorm:"PRICEQTY"` // 指定价类总量 Pointqty float64 `json:"pointqty" xorm:"POINTQTY"` // 点价类总量 Unpricedqty float64 `json:"unpricedqty" xorm:"UNPRICEDQTY"` // 未确定量 Unpricedrelatedqty float64 `json:"unpricedrelatedqty" xorm:"UNPRICEDRELATEDQTY"` // 未确定量关联量 Unpricedavaliableqty float64 `json:"unpricedavaliableqty" xorm:"UNPRICEDAVALIABLEQTY"` // 未确定量可关联量 Unpricedcancelledqty float64 `json:"unpricedcancelledqty" xorm:"UNPRICEDCANCELLEDQTY"` // 未确定量撤销量(非业务) Pricedqty float64 `json:"pricedqty" xorm:"PRICEDQTY"` // 确定量 Pricedamount float64 `json:"pricedamount" xorm:"PRICEDAMOUNT"` // 确定金额 Pricedrelatedqty float64 `json:"pricedrelatedqty" xorm:"PRICEDRELATEDQTY"` // 确定量关联量 Pricedavaliableqty float64 `json:"pricedavaliableqty" xorm:"PRICEDAVALIABLEQTY"` // 确定量可关联量 Pricedcancelledqty float64 `json:"pricedcancelledqty" xorm:"PRICEDCANCELLEDQTY"` // 确定量撤销量(非业务) Pricedcancelledamount float64 `json:"pricedcancelledamount" xorm:"PRICEDCANCELLEDAMOUNT"` // 确定量撤销金额(非业务) Deliveryqty float64 `json:"deliveryqty" xorm:"DELIVERYQTY"` // 交收数量(非业务) Deliveryamount float64 `json:"deliveryamount" xorm:"DELIVERYAMOUNT"` // 交收金额(非业务) Deliveryovershortqty float64 `json:"deliveryovershortqty" xorm:"DELIVERYOVERSHORTQTY"` // 交收溢短数量(非业务) Deliveryactualamount float64 `json:"deliveryactualamount" xorm:"DELIVERYACTUALAMOUNT"` // 交收实际金额(非业务) Deliveryotheramount float64 `json:"deliveryotheramount" xorm:"DELIVERYOTHERAMOUNT"` // 交收其它费用(非业务) Curdeliveryqty float64 `json:"curdeliveryqty" xorm:"CURDELIVERYQTY"` // 剩余交收数量 Curdeliveryamount float64 `json:"curdeliveryamount" xorm:"CURDELIVERYAMOUNT"` // 剩余交收金额 Remark string `json:"remark" xorm:"REMARK"` // 备注 Marketid int64 `json:"marketid" xorm:"MARKETID"` // 市场ID Handlestatus int32 `json:"handlestatus" xorm:"HANDLESTATUS"` // 处理状态 Updatetime time.Time `json:"updatetime" xorm:"UPDATETIME"` // 更新时间 Reckonedamount float64 `json:"reckonedamount" xorm:"RECKONEDAMOUNT"` // 已结金额 Invoicedamount float64 `json:"invoicedamount" xorm:"INVOICEDAMOUNT"` // 已开票金额 } // TableName is ERMS3_SPOTCONTRACTDETAIL func (Erms3Spotcontractdetail) TableName() string { return "ERMS3_SPOTCONTRACTDETAIL" } // 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'"` // 审核备注 } // TableName is ERMS3_SPOTCONTRACTAPPLY 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'), ?, ?, ?, ?, ?, ?, ?, ?, ?, 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 } // GetSpotContractByParams 根据参数来获取合同. func GetSpotContractByParams(accountids string, contracttype int32, contractmode int32, status int32) ([]Erms3Spotcontract, error) { engine := db.GetEngine() strids := strings.Split(accountids, ",") ids := make([]int64, len(strids)) for i := range strids { id, err := strconv.ParseInt(strids[i], 10, 64) if err != nil { return nil, err } ids[i] = id } scs := make([]Erms3Spotcontract, 0) err := engine.Where("CONTRACTMODE = ? and CONTRACTTYPE = ? and CLOSESTATUS = ?", contractmode, contracttype, status).In("ACCOUNTID", ids).Find(&scs) return scs, err } // GetSpotContractDetailByID 根据合同ID来获取明细. func GetSpotContractDetailByID(spotcontractids []string) ([]Erms3Spotcontractdetail, error) { engine := db.GetEngine() details := make([]Erms3Spotcontractdetail, 0) err := engine.In("SPOTCONTRACTID", spotcontractids).Find(&details) return details, err }