Jelajahi Sumber

仓单贸易查成交、查协议单、查交收、查指定成交 增加时间范围过滤条件

zou.yingbin 4 tahun lalu
induk
melakukan
a19534c4a6
7 mengubah file dengan 393 tambahan dan 2 penghapusan
  1. 2 0
      controllers/tjmd/qryTjmd.go
  2. 6 0
      controllers/wrTrade2/qryWrTrade.go
  3. 80 0
      docs/docs.go
  4. 80 0
      docs/swagger.json
  5. 56 0
      docs/swagger.yaml
  6. 11 0
      models/tjmd.go
  7. 158 2
      models/wrTrade2.go

+ 2 - 0
controllers/tjmd/qryTjmd.go

@@ -62,6 +62,8 @@ func QueryTjmdTradeOrderDetail(c *gin.Context) {
 // @Param applytype query int true "类型  1-我的申请 2-对方申请"
 // @Param marketids query string false "市场id, 格式 1,2,3"
 // @Param accountids query string false "资金账号, 格式 25000000001,25000000003"
+// @Param begindate query string false "开始交易日(yyyymmdd)"
+// @Param enddate query string false "结束交易日(yyyymmdd)"
 // @Success 200 {array} models.TjmdTransferApply
 // @Failure 500 {object} app.Response
 // @Router /Tjmd/QueryTjmdTransferApply [get]

+ 6 - 0
controllers/wrTrade2/qryWrTrade.go

@@ -166,6 +166,8 @@ func QueryWrSpecialMatchOrder(c *gin.Context) {
 // @Param userid query int true "用户id"
 // @Param marketid query int false "仓单贸易市场id"
 // @Param haswr query int true "0:仓单预售 1:仓单贸易"
+// @Param begindate query string false "开始交易日(yyyymmdd)"
+// @Param enddate query string false "结束交易日(yyyymmdd)"
 // @Success 200 {array} models.WrTradeDetail
 // @Failure 500 {object} app.Response
 // @Router /WrTrade2/QueryWrTradeDetail [get]
@@ -435,6 +437,8 @@ func QueryWrScfContractInterest(c *gin.Context) {
 // @Produce json
 // @Security ApiKeyAuth
 // @Param userid query int true "用户id"
+// @Param begindate query string false "开始交易日(yyyymmdd)"
+// @Param enddate query string false "结束交易日(yyyymmdd)"
 // @Success 200 {array} models.WrOutInApply
 // @Failure 500 {object} app.Response
 // @Router /WrTrade2/QueryWrOutInApply [get]
@@ -452,6 +456,8 @@ func QueryWrOutInApply(c *gin.Context) {
 // @Security ApiKeyAuth
 // @Param userid query int true "用户id"
 // @Param accountid query int false "资金账号id"
+// @Param begindate query string false "开始交易日(yyyymmdd)"
+// @Param enddate query string false "结束交易日(yyyymmdd)"
 // @Success 200 {array} models.WrDeliveryDetail
 // @Failure 500 {object} app.Response
 // @Router /WrTrade2/QueryWrDeliveryDetail [get]

+ 80 - 0
docs/docs.go

@@ -11319,6 +11319,18 @@ var doc = `{
                         "description": "资金账号, 格式 25000000001,25000000003",
                         "name": "accountids",
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "开始交易日(yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "结束交易日(yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -12918,6 +12930,18 @@ var doc = `{
                         "description": "资金账号id",
                         "name": "accountid",
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "开始交易日(yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "结束交易日(yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -13311,6 +13335,18 @@ var doc = `{
                         "name": "userid",
                         "in": "query",
                         "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "开始交易日(yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "结束交易日(yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -13818,6 +13854,18 @@ var doc = `{
                         "name": "haswr",
                         "in": "query",
                         "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "开始交易日(yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "结束交易日(yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -32556,10 +32604,18 @@ var doc = `{
                     "description": "审核备注(拒绝原因?)",
                     "type": "string"
                 },
+                "begindate": {
+                    "description": "开始交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "buyorsell": {
                     "description": "买卖 - 0:买 1:卖",
                     "type": "integer"
                 },
+                "enddate": {
+                    "description": "结束交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "goodscode": {
                     "description": "商品代码",
                     "type": "string"
@@ -33837,6 +33893,10 @@ var doc = `{
                     "description": "交割均价 = 交割金额 / 交割数量",
                     "type": "number"
                 },
+                "begindate": {
+                    "description": "开始交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "buyorsell": {
                     "description": "方向 -  0:买   1:卖",
                     "type": "integer"
@@ -33873,6 +33933,10 @@ var doc = `{
                     "description": "交收金额",
                     "type": "number"
                 },
+                "enddate": {
+                    "description": "结束交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "enumdicname": {
                     "description": "单位名称",
                     "type": "string"
@@ -35226,6 +35290,10 @@ var doc = `{
                     "description": "申请类型 - 1:预约入库 2:预约出库 3:入库注册 4:出库注销",
                     "type": "integer"
                 },
+                "begindate": {
+                    "description": "开始交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "deliverygoodscode": {
                     "description": "品种代码",
                     "type": "string"
@@ -35238,6 +35306,10 @@ var doc = `{
                     "description": "品种名称",
                     "type": "string"
                 },
+                "enddate": {
+                    "description": "结束交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "enumdicname": {
                     "description": "单位名称",
                     "type": "string"
@@ -36574,6 +36646,10 @@ var doc = `{
                     "description": "资金账号",
                     "type": "integer"
                 },
+                "begindate": {
+                    "description": "开始交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "buyorsell": {
                     "description": "买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)",
                     "type": "integer"
@@ -36598,6 +36674,10 @@ var doc = `{
                     "description": "交收月",
                     "type": "string"
                 },
+                "enddate": {
+                    "description": "结束交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "enumdicname": {
                     "description": "单位名称",
                     "type": "string"

+ 80 - 0
docs/swagger.json

@@ -11303,6 +11303,18 @@
                         "description": "资金账号, 格式 25000000001,25000000003",
                         "name": "accountids",
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "开始交易日(yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "结束交易日(yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -12902,6 +12914,18 @@
                         "description": "资金账号id",
                         "name": "accountid",
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "开始交易日(yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "结束交易日(yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -13295,6 +13319,18 @@
                         "name": "userid",
                         "in": "query",
                         "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "开始交易日(yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "结束交易日(yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -13802,6 +13838,18 @@
                         "name": "haswr",
                         "in": "query",
                         "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "开始交易日(yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "结束交易日(yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -32540,10 +32588,18 @@
                     "description": "审核备注(拒绝原因?)",
                     "type": "string"
                 },
+                "begindate": {
+                    "description": "开始交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "buyorsell": {
                     "description": "买卖 - 0:买 1:卖",
                     "type": "integer"
                 },
+                "enddate": {
+                    "description": "结束交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "goodscode": {
                     "description": "商品代码",
                     "type": "string"
@@ -33821,6 +33877,10 @@
                     "description": "交割均价 = 交割金额 / 交割数量",
                     "type": "number"
                 },
+                "begindate": {
+                    "description": "开始交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "buyorsell": {
                     "description": "方向 -  0:买   1:卖",
                     "type": "integer"
@@ -33857,6 +33917,10 @@
                     "description": "交收金额",
                     "type": "number"
                 },
+                "enddate": {
+                    "description": "结束交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "enumdicname": {
                     "description": "单位名称",
                     "type": "string"
@@ -35210,6 +35274,10 @@
                     "description": "申请类型 - 1:预约入库 2:预约出库 3:入库注册 4:出库注销",
                     "type": "integer"
                 },
+                "begindate": {
+                    "description": "开始交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "deliverygoodscode": {
                     "description": "品种代码",
                     "type": "string"
@@ -35222,6 +35290,10 @@
                     "description": "品种名称",
                     "type": "string"
                 },
+                "enddate": {
+                    "description": "结束交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "enumdicname": {
                     "description": "单位名称",
                     "type": "string"
@@ -36558,6 +36630,10 @@
                     "description": "资金账号",
                     "type": "integer"
                 },
+                "begindate": {
+                    "description": "开始交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "buyorsell": {
                     "description": "买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)",
                     "type": "integer"
@@ -36582,6 +36658,10 @@
                     "description": "交收月",
                     "type": "string"
                 },
+                "enddate": {
+                    "description": "结束交易日(yyyymmdd)",
+                    "type": "string"
+                },
                 "enumdicname": {
                     "description": "单位名称",
                     "type": "string"

+ 56 - 0
docs/swagger.yaml

@@ -13729,9 +13729,15 @@ definitions:
       auditremark:
         description: 审核备注(拒绝原因?)
         type: string
+      begindate:
+        description: 开始交易日(yyyymmdd)
+        type: string
       buyorsell:
         description: 买卖 - 0:买 1:卖
         type: integer
+      enddate:
+        description: 结束交易日(yyyymmdd)
+        type: string
       goodscode:
         description: 商品代码
         type: string
@@ -14677,6 +14683,9 @@ definitions:
       averageprice:
         description: 交割均价 = 交割金额 / 交割数量
         type: number
+      begindate:
+        description: 开始交易日(yyyymmdd)
+        type: string
       buyorsell:
         description: 方向 -  0:买   1:卖
         type: integer
@@ -14704,6 +14713,9 @@ definitions:
       deliverytotalamount:
         description: 交收金额
         type: number
+      enddate:
+        description: 结束交易日(yyyymmdd)
+        type: string
       enumdicname:
         description: 单位名称
         type: string
@@ -15705,6 +15717,9 @@ definitions:
       applytype:
         description: 申请类型 - 1:预约入库 2:预约出库 3:入库注册 4:出库注销
         type: integer
+      begindate:
+        description: 开始交易日(yyyymmdd)
+        type: string
       deliverygoodscode:
         description: 品种代码
         type: string
@@ -15714,6 +15729,9 @@ definitions:
       deliverygoodsname:
         description: 品种名称
         type: string
+      enddate:
+        description: 结束交易日(yyyymmdd)
+        type: string
       enumdicname:
         description: 单位名称
         type: string
@@ -16703,6 +16721,9 @@ definitions:
       accountid:
         description: 资金账号
         type: integer
+      begindate:
+        description: 开始交易日(yyyymmdd)
+        type: string
       buyorsell:
         description: 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
         type: integer
@@ -16721,6 +16742,9 @@ definitions:
       deliverymonth:
         description: 交收月
         type: string
+      enddate:
+        description: 结束交易日(yyyymmdd)
+        type: string
       enumdicname:
         description: 单位名称
         type: string
@@ -26084,6 +26108,14 @@ paths:
         in: query
         name: accountids
         type: string
+      - description: 开始交易日(yyyymmdd)
+        in: query
+        name: begindate
+        type: string
+      - description: 结束交易日(yyyymmdd)
+        in: query
+        name: enddate
+        type: string
       produces:
       - application/json
       responses:
@@ -27095,6 +27127,14 @@ paths:
         in: query
         name: accountid
         type: integer
+      - description: 开始交易日(yyyymmdd)
+        in: query
+        name: begindate
+        type: string
+      - description: 结束交易日(yyyymmdd)
+        in: query
+        name: enddate
+        type: string
       produces:
       - application/json
       responses:
@@ -27342,6 +27382,14 @@ paths:
         name: userid
         required: true
         type: integer
+      - description: 开始交易日(yyyymmdd)
+        in: query
+        name: begindate
+        type: string
+      - description: 结束交易日(yyyymmdd)
+        in: query
+        name: enddate
+        type: string
       produces:
       - application/json
       responses:
@@ -27664,6 +27712,14 @@ paths:
         name: haswr
         required: true
         type: integer
+      - description: 开始交易日(yyyymmdd)
+        in: query
+        name: begindate
+        type: string
+      - description: 结束交易日(yyyymmdd)
+        in: query
+        name: enddate
+        type: string
       produces:
       - application/json
       responses:

+ 11 - 0
models/tjmd.go

@@ -164,6 +164,9 @@ type TjmdTransferApply struct {
 	ApplyType    int32  `json:"-" form:"applytype"`  // 类型  1-我的申请 2-对方申请
 	FtMarketIds  string `json:"-" form:"marketids"`  // 市场 格式 1,2,3
 	FtAccountIds string `json:"-" form:"accountids"` // 资金账号 格式 1,2,3
+
+	BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
+	ENDDATE   string `json:"enddate" form:"enddate"`     // 结束交易日(yyyymmdd)
 }
 
 func (r *TjmdTransferApply) calc() {
@@ -193,6 +196,14 @@ select t.applyid,
     on t.goodsid = g.goodsid
   where 1=1
 `
+	// 格式 yyyymmdd
+	if len(r.BEGINDATE) > 0 {
+		sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
+	}
+
+	if len(r.ENDDATE) > 0 {
+		sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
+	}
 	sqlId.JoinEx(r.FtMarketIds != "", fmt.Sprintf(" and t.marketid in(%v)", r.FtMarketIds))
 	if r.ApplyType == 1 {
 		sqlId.JoinEx(r.FtAccountIds != "", fmt.Sprintf(" and t.outaccountid in(%v)", r.FtAccountIds))

+ 158 - 2
models/wrTrade2.go

@@ -924,6 +924,9 @@ type WrTradeDetail struct {
 	MATCHUSERNAME   string  `json:"matchusername"  xorm:"'MATCHUSERNAME'"`              // 对手方
 	Wr2FactorType   `xorm:"extends"`
 	PageEx          `xorm:"extends"`
+
+	BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
+	ENDDATE   string `json:"enddate" form:"enddate"`     // 结束交易日(yyyymmdd)
 }
 
 func (r *WrTradeDetail) calc() {
@@ -982,10 +985,76 @@ func (r *WrTradeDetail) buildSql() string {
 	return sqlId.String()
 }
 
+func (r *WrTradeDetail) buildSqlHis() string {
+	var sqlId utils.SQLVal = "with tmp as" +
+		" (select to_char(t.wrfactortypeid) wrfactortypeid," +
+		"         t.wrfactortypename," +
+		"         t.wrstandardid," +
+		"         t.deliverygoodsid," +
+		"         g.deliverygoodscode," +
+		"         g.deliverygoodsname," +
+		"         w.wrstandardcode," +
+		"         w.wrstandardname," +
+		"         h.warehousecode," +
+		"         h.warehousename," +
+		"         e.enumdicname," +
+		"         w.wrstandardname || t.wrfactortypename2 as wrtypename" +
+		"    from wrfactortype t" +
+		"    left join deliverygoods g" +
+		"      on t.deliverygoodsid = g.deliverygoodsid" +
+		"    left join wrstandard w" +
+		"      on t.wrstandardid = w.wrstandardid" +
+		"    left join warehouseinfo h" +
+		"      on t.warehouseid = h.autoid" +
+		"    left join enumdicitem e on w.unitid = e.enumitemname and e.enumdiccode='goodsunit')" +
+		"select t.HASWR," +
+		"       to_char(t.WRTRADEDETAILID) WRTRADEDETAILID," +
+		"       t.TRADEDATE," +
+		"       t.DELIVERYMONTH," +
+		"       t.WRTRADETYPE," +
+		"       t.BUYORSELL," +
+		"       t.MARKETID," +
+		"       t.TRADEQTY," +
+		"       t.TRADEPRICE," +
+		"       t.CHARGEVALUE," +
+		"       to_char(t.TRADETIME,'yyyy-mm-dd hh24:mi:ss') TRADETIME," +
+		"       u2.accountname matchusername," +
+		"       ta1.userid," +
+		"       k.*" +
+		"  from his_wrtrade_tradedetail t" +
+		"  left join tmp k" +
+		"    on t.wrfactortypeid = k.wrfactortypeid" +
+		"  left join taaccount ta1 on t.accountid=ta1.accountid" +
+		"  left join taaccount ta2 on t.matchaccountid=ta2.accountid" +
+		"  left join useraccount u2 on ta2.userid=u2.userid" +
+		"  where 1=1"
+	sqlId.And("ta1.userid", r.USERID)
+	sqlId.And("t.haswr", r.HASWR)
+	sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
+	// 格式 yyyymmdd
+	if len(r.BEGINDATE) > 0 {
+		sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
+	}
+
+	if len(r.ENDDATE) > 0 {
+		sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
+	}
+	sqlId.Join(" order by t.tradetime desc")
+	sqlId.Page(r.Page, r.PageSize)
+	return sqlId.String()
+}
+
 // GetDataByPage 获取仓单贸易成交明细
 func (r *WrTradeDetail) GetDataByPage() (interface{}, error, int, int, int) {
+	var sqlId string
+	// 如果指定了开始日期或结束日期, 刚查历史
+	if r.BEGINDATE != "" || r.ENDDATE != "" {
+		sqlId = r.buildSqlHis()
+	} else {
+		sqlId = r.buildSql()
+	}
 	sData := make([]WrTradeDetail, 0)
-	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	err := db.GetEngine().SQL(sqlId).Find(&sData)
 	total := 0
 	for i := range sData {
 		sData[i].calc()
@@ -2646,6 +2715,9 @@ type WrOutInApply struct {
 	EXPRESSNUM     string `json:"expressnum"  xorm:"'EXPRESSNUM'"`         // 物流单号
 	EXPRESSCOMPANY string `json:"expresscompany"  xorm:"'EXPRESSCOMPANY'"` // 物流公司
 	Wr2FactorType  `xorm:"extends"`
+
+	BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
+	ENDDATE   string `json:"enddate" form:"enddate"`     // 结束交易日(yyyymmdd)
 }
 
 func (r *WrOutInApply) calc() {
@@ -2696,6 +2768,14 @@ func (r *WrOutInApply) buildSql() string {
 		"    on d.wrfactortypeid = k.wrfactortypeid" +
 		" where t.applytype in (2, 4)"
 	sqlId.AndEx("t.USERID", r.USERID, r.USERID > 0)
+	// 格式 yyyymmdd
+	if len(r.BEGINDATE) > 0 {
+		sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
+	}
+
+	if len(r.ENDDATE) > 0 {
+		sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
+	}
 	sqlId.Join(" order by t.applytime desc")
 	return sqlId.String()
 }
@@ -2745,6 +2825,9 @@ type WrDeliveryDetail struct {
 
 	XGOODSAMOUNT SFLOAT64 `json:"xgoodsamount"` // 合约金额 = 货款金额(DELIVERYAMOUNT) - 点价货款(P1GOODSREMAINAMOUNT)
 	AVERAGEPRICE SFLOAT64 `json:"averageprice"` // 交割均价 = 交割金额 / 交割数量
+
+	BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
+	ENDDATE   string `json:"enddate" form:"enddate"`     // 结束交易日(yyyymmdd)
 }
 
 func (r *WrDeliveryDetail) calc() {
@@ -2817,10 +2900,83 @@ select t.xgoodsid,
 	return sqlId.String()
 }
 
+func (r *WrDeliveryDetail) buildSqlHis() string {
+	var sqlId utils.SQLVal = `
+select t.xgoodsid,
+       t.buyorsell,
+       to_char(t.deliveryid) deliveryid,
+       t.deliveryqty,
+       t.xdeliverycloseqty,
+       t.pdeliverycloseqty,
+       t.deliveryamount,
+       t.pdeliveryprice,
+       t.p1goodsremainamount,
+       t.deliverypricemove,
+       t.deliverytotalamount,
+       to_char(t.deliverytime, 'yyyy-mm-dd hh24:mi:ss') deliverytime,
+       t.deliverystatus,
+       t.accountid,
+       t.matchaccountid,
+       t.tradedate,
+       to_char(t.wrfactortypeid) wrfactortypeid,
+       to_char(t.deliveryorderid) deliveryorderid,
+       g.goodscode xgoodscode,
+       g.goodsname xgoodsname,
+       t.pgoodsid,
+       g2.goodscode pgoodscode,
+       g2.goodsname pgoodsname,
+       ta.accountname taaccountname,
+       u.userid,
+       u.accountname username,
+       u2.accountname matchusername,
+       wd.wrstandardname || w.wrfactortypename2 as WRTYPENAME,
+       h.warehousename,
+       e.enumdicname
+  from his_deliverydetail t
+  left join goods g
+    on t.xgoodsid = g.goodsid
+  left join goods g2
+    on t.pgoodsid = g2.goodsid
+  left join taaccount ta
+    on t.accountid = ta.accountid
+  left join useraccount u
+    on ta.userid = u.userid
+  left join taaccount ta2
+    on t.accountid = ta2.accountid
+  left join useraccount u2
+    on ta2.userid = u2.userid
+  left join wrfactortype w
+    on t.wrfactortypeid = w.wrfactortypeid
+  left join wrstandard wd
+    on w.wrstandardid = wd.wrstandardid
+  left join warehouseinfo h on w.warehouseid=h.autoid
+  left join enumdicitem e on wd.unitid=e.enumitemname and e.enumdiccode='goodsunit'
+ where 1 = 1
+`
+	sqlId.AndEx("u.userid", r.USERID, r.USERID > 0)
+	sqlId.AndEx("t.accountid", r.ACCOUNTID, r.ACCOUNTID > 0)
+	// 格式 yyyymmdd
+	if len(r.BEGINDATE) > 0 {
+		sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
+	}
+
+	if len(r.ENDDATE) > 0 {
+		sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
+	}
+	return sqlId.String()
+}
+
 // GetDataEx 获取交收
 func (r *WrDeliveryDetail) GetDataEx() (interface{}, error) {
+	var sqlId string
+	// 如果指定了开始日期或结束日期, 刚查历史
+	if r.BEGINDATE != "" || r.ENDDATE != "" {
+		sqlId = r.buildSqlHis()
+	} else {
+		sqlId = r.buildSql()
+	}
 	sData := make([]WrDeliveryDetail, 0)
-	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	err := db.GetEngine().SQL(sqlId).Find(&sData)
 	for i := range sData {
 		sData[i].calc()
 	}