|
|
@@ -4,12 +4,15 @@ import (
|
|
|
"encoding/hex"
|
|
|
"encoding/json"
|
|
|
"math"
|
|
|
+ "mtp2_if/db"
|
|
|
"mtp2_if/global/app"
|
|
|
"mtp2_if/global/e"
|
|
|
"mtp2_if/logger"
|
|
|
"mtp2_if/models"
|
|
|
"mtp2_if/utils"
|
|
|
"net/http"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
@@ -427,3 +430,158 @@ func QuerySpotContractAppleForm(c *gin.Context) {
|
|
|
logger.GetLogger().Debugln("QuerySpotContractAppleForm successed: %v", rsp)
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, rsp)
|
|
|
}
|
|
|
+
|
|
|
+// QuerySpotContractInfoReq 查询合同明细请求.
|
|
|
+type QuerySpotContractInfoReq struct {
|
|
|
+ Accountids string `form:"accountids" binding:"required"` // 资金账号ID列表,逗号分隔.
|
|
|
+ ContractType int32 `form:"contracttype" binding:"required"` // 合同类型,1-采购合同 2-销售合同.
|
|
|
+ ContractMode int32 `form:"contractmode" binding:"required"` // 合同模式,1-普通合同 2-回购销售合同.
|
|
|
+ Status int32 `form:"status"` // 合同状态,0-履约中 1-已完成.
|
|
|
+}
|
|
|
+
|
|
|
+// QuerySpotContractInfoRsp 查询合同明细响应.
|
|
|
+type QuerySpotContractInfoRsp struct {
|
|
|
+ SpotContractID string `json:"spotcontractid"` // 合同ID
|
|
|
+ CustomerName string `json:"customername"` // 若合同类型为采购合同,表示采购方ID;若合同类型为销售合同,表示销售方ID.
|
|
|
+ AccountID int64 `json:"accountid"` // 表示交易员ID.
|
|
|
+ MatchCustomerName string `json:"matchcustomername"` // 若合同类型为采购合同,表示销售方;若合同类型为销售合同,表示采购方ID.
|
|
|
+ MatchAccountID int64 `json:"matchaccountid"` // 表示业务员ID.
|
|
|
+ WRStandardName string `json:"wrstandardname"` // 表示商品ID.
|
|
|
+ TotalQty float64 `json:"totalqty"` // 表示合同量.
|
|
|
+ PricedQty float64 `json:"priceqty"` // 表示定价量.
|
|
|
+ UnPricedQty float64 `json:"unpricedqty"` // 表示未定价量.
|
|
|
+ DeliveryQty float64 `json:"deliveryqty"` // 表示交收量.
|
|
|
+ CurDeliveryQty float64 `json:"curdeliveryqty"` // 表示未交收量.
|
|
|
+ SignDate string `json:"signdate"` // 表示签订日期.
|
|
|
+ DeliveryGoodsID string `json:"deliverygoodsid"` // 表示品种ID.
|
|
|
+ RelatedBizID string `json:"relatedbizid"` // 表示业务ID.
|
|
|
+ Status int32 `json:"status"` // 表示状态,0-履约中 1-已完成.
|
|
|
+}
|
|
|
+
|
|
|
+// QuerySpotContractDetail 查询合同详细信息.
|
|
|
+// @Summary 查询合同详细信息
|
|
|
+// @Produce json
|
|
|
+// @Security ApiKeyAuth
|
|
|
+// @Param accountids query string true "资金账号ID列表,用逗号分隔"
|
|
|
+// @Param contracttype query int true "合同类型,1-采购合同 2-销售合同"
|
|
|
+// @Param contractmode query int true "合同模式,1-普通合同 2-回购销售合同"
|
|
|
+// @Param status query int true "状态,0-履约中 1-已完成"
|
|
|
+// @Success 200 {array} QuerySpotContractInfoRsp
|
|
|
+// @Failure 500 {object} app.Response
|
|
|
+// @Router /Erms3/QuerySpotContractDetail [get]
|
|
|
+// @Tags 风险管理v3
|
|
|
+func QuerySpotContractDetail(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+
|
|
|
+ // 获取请求参数
|
|
|
+ var req QuerySpotContractInfoReq
|
|
|
+ err := appG.C.ShouldBindQuery(&req)
|
|
|
+ if err != nil {
|
|
|
+ logger.GetLogger().Errorf("QuerySpotContractDetail failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ strids := strings.Split(strings.TrimSpace(req.Accountids), ",")
|
|
|
+ accountids := make([]int64, len(strids))
|
|
|
+ for i := range strids {
|
|
|
+ accountids[i], err = strconv.ParseInt(strids[i], 10, 64)
|
|
|
+ if err != nil {
|
|
|
+ logger.GetLogger().Errorf("ParseInt failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询数据.
|
|
|
+ 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 {
|
|
|
+ // 查询失败
|
|
|
+ logger.GetLogger().Errorf("QuerySpotContract failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ userids := make(map[int64]struct{})
|
|
|
+ for i := range datas {
|
|
|
+ userids[datas[i].Areauserid] = struct{}{}
|
|
|
+ userids[datas[i].Customeruserid] = struct{}{}
|
|
|
+ }
|
|
|
+
|
|
|
+ arrayids := make([]int64, 0, len(userids))
|
|
|
+ for k, _ :=range userids {
|
|
|
+ arrayids = append(arrayids, k)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取所有用户信息.
|
|
|
+ userinfos, err := models.GetUserInfoByIDS(arrayids)
|
|
|
+ if err != nil {
|
|
|
+ // 查询失败
|
|
|
+ logger.GetLogger().Errorf("QueryUserInfo failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ userid2names := make(map[int64]string, len(userinfos))
|
|
|
+ for i := range userinfos {
|
|
|
+ userid2names[userinfos[i].Userid] = userinfos[i].Customername
|
|
|
+ }
|
|
|
+
|
|
|
+ infos := make([]QuerySpotContractInfoRsp, 0, len(datas))
|
|
|
+ for i := range datas {
|
|
|
+ infos = append(infos, QuerySpotContractInfoRsp{
|
|
|
+ SpotContractID: datas[i].Spotcontractid,
|
|
|
+ CustomerName: userid2names[datas[i].Areauserid],
|
|
|
+ AccountID: datas[i].Accountid,
|
|
|
+ MatchCustomerName: userid2names[datas[i].Customeruserid],
|
|
|
+ MatchAccountID: datas[i].Customeraccountid,
|
|
|
+ WRStandardName: strings.Join([]string{datas[i].Wrstandardname, datas[i].Wrstandardcode}, "/"),
|
|
|
+ TotalQty: datas[i].Pricedqty - datas[i].Pricedcancelledqty + datas[i].Unpricedqty - datas[i].Unpricedcancelledqty,
|
|
|
+ PricedQty: datas[i].Pricedqty - datas[i].Pricedcancelledqty,
|
|
|
+ UnPricedQty: datas[i].Unpricedqty - datas[i].Unpricedcancelledqty,
|
|
|
+ DeliveryQty: datas[i].Deliveryqty,
|
|
|
+ CurDeliveryQty: datas[i].Curdeliveryqty,
|
|
|
+ SignDate: datas[i].Signdate.Format("2006-01-02"),
|
|
|
+ DeliveryGoodsID: strings.Join([]string{datas[i].Deliverygoodsname, datas[i].Deliverygoodscode}, "/"),
|
|
|
+ RelatedBizID: datas[i].Relatedbizid,
|
|
|
+ Status: datas[i].Closestatus,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询成功
|
|
|
+ logger.GetLogger().Debugln("QuerySpotContractDetail successed: %v", infos)
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, infos)
|
|
|
+}
|