taaccount.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package taaccount
  2. import (
  3. "fmt"
  4. "mtp2_if/db"
  5. "mtp2_if/global/app"
  6. "mtp2_if/global/e"
  7. "mtp2_if/logger"
  8. "mtp2_if/models"
  9. "net/http"
  10. "github.com/gin-gonic/gin"
  11. )
  12. // GetTaAccountsReq 获取资金账户请求参数
  13. type GetTaAccountsReq struct {
  14. LoginID int `form:"loginID" binding:"required"`
  15. TaAccountType int `form:"taAccountType"`
  16. }
  17. // GetTaAccounts 获取资金账户信息
  18. // @Summary 获取资金账户信息
  19. // @Produce json
  20. // @Security ApiKeyAuth
  21. // @Param loginID query int true "登录账户"
  22. // @Param taAccountType query int false "账号类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号"
  23. // @Success 200 {object} models.Taaccount
  24. // @Failure 500 {object} app.Response
  25. // @Router /TaAccount/GetTaAccounts [get]
  26. // @Tags 资金账户
  27. func GetTaAccounts(c *gin.Context) {
  28. appG := app.Gin{C: c}
  29. // 获取请求参数
  30. var req GetTaAccountsReq
  31. if err := appG.C.ShouldBindQuery(&req); err != nil {
  32. logger.GetLogger().Errorf("GetTaAccounts failed: %s", err.Error())
  33. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  34. return
  35. }
  36. // 查询数据
  37. taAccounts, err := models.GetTaAccountsByLoginID(req.LoginID, req.TaAccountType)
  38. if err != nil {
  39. // 查询失败
  40. logger.GetLogger().Errorf("GetTaAccounts failed: %s", err.Error())
  41. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  42. return
  43. }
  44. // 查询成功
  45. logger.GetLogger().Debugln("GetTaAccounts successed: %v", taAccounts)
  46. appG.Response(http.StatusOK, e.SUCCESS, taAccounts)
  47. }
  48. // QueryAmountLogReq 资金流水查询(当前)请求参数
  49. type QueryAmountLogReq struct {
  50. app.PageInfo
  51. AccountID string `form:"accountID"` // 资金账户
  52. OperateType string `form:"operateType"` // 资金操作类型
  53. }
  54. // QueryAmountLogRsp 资金流水查询(当前)返回模型
  55. type QueryAmountLogRsp struct {
  56. models.Taaccountlog `xorm:"extends"`
  57. MarketName string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
  58. TradeMode uint32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
  59. GoodsCode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  60. GoodsName string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  61. AGoodsCode string `json:"agoodscode" xorm:"'AGOODSCODE'"` // 竞拍商品代码
  62. AGoodsName string `json:"agoodsname" xorm:"'GOODSNAME'"` // 竞拍商品名称
  63. DGoodsCode string `json:"dgoodscode" xorm:"'DGOODSCODE'"` // 交割商品代码
  64. DGoodsName string `json:"dgoodsname" xorm:"'DGOODSNAME'"` // 交割商品名称
  65. OperateTypeName string `json:"OPERATETYPENAME" xorm:"OPERATETYPENAME"` // 资金操作类型名称
  66. }
  67. // QueryAmountLog 资金流水查询(当前)
  68. // @Summary 资金流水查询(当前)
  69. // @Produce json
  70. // @Security ApiKeyAuth
  71. // @Param page query int false "页码"
  72. // @Param pagesize query int false "每页条数"
  73. // @Param accountID query string true "资金账户 - 格式:1,2,3"
  74. // @Param OperateType query string false "资金操作类型 - 格式:1,2,3"
  75. // @Success 200 {object} QueryAmountLogRsp
  76. // @Failure 500 {object} app.Response
  77. // @Router /TaAccount/QueryAmountLog [get]
  78. // @Tags 资金账户
  79. // 参考通用查询:QueryClientAmountLog
  80. func QueryAmountLog(c *gin.Context) {
  81. appG := app.Gin{C: c}
  82. // 获取请求参数
  83. var req QueryAmountLogReq
  84. if err := appG.C.ShouldBindQuery(&req); err != nil {
  85. logger.GetLogger().Errorf("QueryAmountLog failed: %s", err.Error())
  86. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  87. return
  88. }
  89. // 查询数据
  90. datas := make([]QueryAmountLogRsp, 0)
  91. engine := db.GetEngine()
  92. s := engine.Table("TAACCOUNTLOG").
  93. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMSTATUS = 1 and ENUMDICITEM.ENUMDICID = 39 and ENUMDICITEM.ENUMITEMNAME = TAACCOUNTLOG.OPERATETYPE").
  94. Join("LEFT", "MARKET", "MARKET.MARKETID = TAACCOUNTLOG.MARKETID").
  95. Join("LEFT", "GOODS", "GOODS.GOODSID = TAACCOUNTLOG.GOODSID").
  96. Join("LEFT", "AUCTION_ORDERINFO", "AUCTION_ORDERINFO.GOODSID = TAACCOUNTLOG.GOODSID").
  97. Join("LEFT", "DELIVERYGOODS", "DELIVERYGOODS.DELIVERYGOODSID = TAACCOUNTLOG.GOODSID").
  98. Select(`to_char(TAACCOUNTLOG.RELATIONORDERID) as RELATIONORDERID, TAACCOUNTLOG.*,
  99. MARKET.MARKETNAME, MARKET.TRADEMODE,
  100. GOODS.GOODSCODE, GOODS.GOODSNAME,
  101. AUCTION_ORDERINFO.GOODSCODE AS AGOODSCODE, AUCTION_ORDERINFO.GOODSNAME AS AGOODSNAME,
  102. DELIVERYGOODS.DELIVERYGOODSCODE AS DGOODSCODE, DELIVERYGOODS.DELIVERYGOODSNAME AS DGOODSNAME,
  103. ENUMDICITEM.ENUMDICNAME AS OPERATETYPENAME`).
  104. Where(fmt.Sprintf("TAACCOUNTLOG.ACCOUNTID in (%s)", req.AccountID)).Desc("TAACCOUNTLOG.AUTOID")
  105. if len(req.OperateType) > 0 {
  106. s = s.And(fmt.Sprintf("TAACCOUNTLOG.OPERATETYPE in (%s)", req.OperateType))
  107. }
  108. if err := s.Find(&datas); err != nil {
  109. // 查询失败
  110. logger.GetLogger().Errorf("QueryAmountLog failed: %s", err.Error())
  111. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  112. return
  113. }
  114. // 查询成功返回
  115. if req.PageSize > 0 {
  116. // 分页
  117. rst := make([]QueryAmountLogRsp, 0)
  118. // 开始上标
  119. start := req.Page * req.PageSize
  120. // 结束下标
  121. end := start + req.PageSize
  122. if start <= len(datas) {
  123. // 判断结束下标是否越界
  124. if end > len(datas) {
  125. end = len(datas)
  126. }
  127. rst = datas[start:end]
  128. } else {
  129. rst = datas[0:0]
  130. }
  131. logger.GetLogger().Debugln("QueryAmountLog successed: %v", rst)
  132. appG.ResponseByPage(http.StatusOK, e.SUCCESS, rst, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: len(datas)})
  133. } else {
  134. // 不分页
  135. logger.GetLogger().Debugln("QueryAmountLog successed: %v", datas)
  136. appG.Response(http.StatusOK, e.SUCCESS, datas)
  137. }
  138. }
  139. // QueryHisAmountLogReq 资金流水查询(历史)请求参数
  140. type QueryHisAmountLogReq struct {
  141. app.PageInfo
  142. AccountID string `form:"accountID"` // 资金账户
  143. OperateType string `form:"operateType"` // 资金操作类型
  144. StartDate string `form:"startDate"` // 开始时间
  145. EndDate string `form:"endDate"` // 结束时间
  146. }
  147. // QueryHisAmountLogRsp 资金流水查询(历史)返回模型
  148. type QueryHisAmountLogRsp struct {
  149. models.Histaaccountlog `xorm:"extends"`
  150. MarketName string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
  151. TradeMode uint32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
  152. GoodsCode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  153. GoodsName string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  154. AGoodsCode string `json:"agoodscode" xorm:"'AGOODSCODE'"` // 竞拍商品代码
  155. AGoodsName string `json:"agoodsname" xorm:"'GOODSNAME'"` // 竞拍商品名称
  156. DGoodsCode string `json:"dgoodscode" xorm:"'DGOODSCODE'"` // 交割商品代码
  157. DGoodsName string `json:"dgoodsname" xorm:"'DGOODSNAME'"` // 交割商品名称
  158. OperateTypeName string `json:"OPERATETYPENAME" xorm:"OPERATETYPENAME"` // 资金操作类型名称
  159. }
  160. // QueryHisAmountLog 资金流水查询(历史)
  161. // @Summary 资金流水查询(历史)
  162. // @Produce json
  163. // @Security ApiKeyAuth
  164. // @Param page query int false "页码"
  165. // @Param pagesize query int false "每页条数"
  166. // @Param accountID query string true "资金账户 - 格式:1,2,3"
  167. // @Param OperateType query string false "资金操作类型 - 格式:1,2,3"
  168. // @Param startDate query string false "开始时间 - 闭区间,格式:yyyy-MM-dd"
  169. // @Param endDate query string false "结束时间 - 闭区间,格式:yyyy-MM-dd"
  170. // @Success 200 {object} QueryHisAmountLogRsp
  171. // @Failure 500 {object} app.Response
  172. // @Router /TaAccount/QueryHisAmountLog [get]
  173. // @Tags 资金账户
  174. // 参考通用查询:Client_QueryHis_taaccountlog
  175. func QueryHisAmountLog(c *gin.Context) {
  176. appG := app.Gin{C: c}
  177. // 获取请求参数
  178. var req QueryHisAmountLogReq
  179. if err := appG.C.ShouldBindQuery(&req); err != nil {
  180. logger.GetLogger().Errorf("QueryHisAmountLog failed: %s", err.Error())
  181. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  182. return
  183. }
  184. // 查询数据
  185. datas := make([]QueryHisAmountLogRsp, 0)
  186. engine := db.GetEngine()
  187. s := engine.Table("HIS_TAACCOUNTLOG").
  188. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMSTATUS = 1 and ENUMDICITEM.ENUMDICID = 39 and ENUMDICITEM.ENUMITEMNAME = HIS_TAACCOUNTLOG.OPERATETYPE").
  189. Join("LEFT", "MARKET", "MARKET.MARKETID = HIS_TAACCOUNTLOG.MARKETID").
  190. Join("LEFT", "GOODS", "GOODS.GOODSID = HIS_TAACCOUNTLOG.GOODSID").
  191. Join("LEFT", "HIS_AUCTION_ORDERINFO", "HIS_AUCTION_ORDERINFO.GOODSID = HIS_TAACCOUNTLOG.GOODSID and HIS_AUCTION_ORDERINFO.ISVALIDDATA = 1").
  192. Join("LEFT", "DELIVERYGOODS", "DELIVERYGOODS.DELIVERYGOODSID = HIS_TAACCOUNTLOG.GOODSID").
  193. Select(`to_char(HIS_TAACCOUNTLOG.RELATIONORDERID) as RELATIONORDERID, HIS_TAACCOUNTLOG.*,
  194. MARKET.MARKETNAME, MARKET.TRADEMODE,
  195. GOODS.GOODSCODE, GOODS.GOODSNAME,
  196. HIS_AUCTION_ORDERINFO.GOODSCODE AS AGOODSCODE, HIS_AUCTION_ORDERINFO.GOODSNAME AS AGOODSNAME,
  197. DELIVERYGOODS.DELIVERYGOODSCODE AS DGOODSCODE, DELIVERYGOODS.DELIVERYGOODSNAME AS DGOODSNAME,
  198. ENUMDICITEM.ENUMDICNAME AS OPERATETYPENAME`).
  199. Where(fmt.Sprintf(`HIS_TAACCOUNTLOG.ISVALIDDATA = 1 and HIS_TAACCOUNTLOG.ACCOUNTID in (%s)`, req.AccountID)).Desc("HIS_TAACCOUNTLOG.AUTOID")
  200. if len(req.OperateType) > 0 {
  201. s = s.And(fmt.Sprintf("HIS_TAACCOUNTLOG.OPERATETYPE in (%s)", req.OperateType))
  202. }
  203. if len(req.StartDate) > 0 {
  204. s = s.And(fmt.Sprintf("to_date(HIS_TAACCOUNTLOG.HISTRADEDATE,'yyyyMMdd') >= to_date('%s','yyyy-MM-dd')", req.StartDate))
  205. }
  206. if len(req.EndDate) > 0 {
  207. s = s.And(fmt.Sprintf("to_date(HIS_TAACCOUNTLOG.HISTRADEDATE,'yyyyMMdd') <= to_date('%s','yyyy-MM-dd')", req.EndDate))
  208. }
  209. if err := s.Find(&datas); err != nil {
  210. // 查询失败
  211. logger.GetLogger().Errorf("QueryHisAmountLog failed: %s", err.Error())
  212. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  213. return
  214. }
  215. // 查询成功返回
  216. if req.PageSize > 0 {
  217. // 分页
  218. rst := make([]QueryHisAmountLogRsp, 0)
  219. // 开始上标
  220. start := req.Page * req.PageSize
  221. // 结束下标
  222. end := start + req.PageSize
  223. if start <= len(datas) {
  224. // 判断结束下标是否越界
  225. if end > len(datas) {
  226. end = len(datas)
  227. }
  228. rst = datas[start:end]
  229. } else {
  230. rst = datas[0:0]
  231. }
  232. logger.GetLogger().Debugln("QueryHisAmountLog successed: %v", rst)
  233. appG.ResponseByPage(http.StatusOK, e.SUCCESS, rst, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: len(datas)})
  234. } else {
  235. // 不分页
  236. logger.GetLogger().Debugln("QueryHisAmountLog successed: %v", datas)
  237. appG.Response(http.StatusOK, e.SUCCESS, datas)
  238. }
  239. }