szdz.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. package szdz
  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. "sort"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // QueryRecieptOrderReq 点选挂牌委托单据查询参数
  14. type QueryRecieptOrderReq struct {
  15. app.PageInfo
  16. GoodsID int `form:"goodsID" binding:"required"` // 商品ID,必填
  17. AccountName string `form:"accountName"` // 所属账户名称
  18. MarketID int `form:"marketID"` // 市场ID
  19. BuyOrSell int `form:"buyorsell"` // 方向
  20. }
  21. // QueryRecieptOrderRsp 点选挂牌委托单据查询返回模型
  22. type QueryRecieptOrderRsp struct {
  23. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
  24. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  25. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  26. Buyorsell uint32 `json:"buyorsell" xorm:"'BUYORSELL'"` // 方向 - 0:买 1:卖
  27. Orderid string `json:"orderid" xorm:"'ORDERID'"` // 委托单号
  28. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  29. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  30. EnableQty int64 `json:"enableqty" xorm:"ENABLEQTY"` // 可摘数量
  31. AccountName string `json:"accountName" xorm:"ACCOUNTNAME"` // 所属账号名称(已脱敏)
  32. }
  33. // QueryRecieptOrder 点选挂牌委托单据查询(摘牌大厅)
  34. // @Summary 点选挂牌委托单据查询(摘牌大厅)
  35. // @Description 说明:pagesize参数赋值不为0时表示需要分页;page参数从0开始计算
  36. // @Produce json
  37. // @Security ApiKeyAuth
  38. // @Param page query int false "页码"
  39. // @Param pagesize query int false "每页条数"
  40. // @Param goodsID query int true "商品ID"
  41. // @Param accountName query string false "所属账户名称"
  42. // @Param marketID query int false "市场ID"
  43. // @Param buyorsell query int false "方向 - 0:买 1:卖"
  44. // @Success 200 {object} QueryRecieptOrderRsp
  45. // @Failure 500 {object} app.Response
  46. // @Router /SZDZ/QueryRecieptOrder [get]
  47. // @Tags 定制【尚志大宗】
  48. func QueryRecieptOrder(c *gin.Context) {
  49. appG := app.Gin{C: c}
  50. // 获取请求参数
  51. var req QueryRecieptOrderReq
  52. req.BuyOrSell = -1 // 买方向值为0,所以要初始赋值
  53. if err := appG.C.ShouldBindQuery(&req); err != nil {
  54. logger.GetLogger().Errorf("QueryRecieptOrder failed: %s", err.Error())
  55. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  56. return
  57. }
  58. datas := make([]QueryRecieptOrderRsp, 0)
  59. engine := db.GetEngine()
  60. // 投资者挂牌委托单
  61. s := engine.Table("TRADE_ORDERDETAIL").
  62. Join("INNER", "GOODS", "TRADE_ORDERDETAIL.GOODSID = GOODS.GOODSID").
  63. Join("LEFT", "TAACCOUNT", "TAACCOUNT.ACCOUNTID = TRADE_ORDERDETAIL.ACCOUNTID").
  64. Join("LEFT", "USERACCOUNT", "USERACCOUNT.USERID = TAACCOUNT.RELATEDUSERID").
  65. Select(`GOODS.GOODSID, GOODS.GOODSCODE, GOODS.GOODSNAME,
  66. TRADE_ORDERDETAIL.BUYORSELL, to_char(TRADE_ORDERDETAIL.ORDERID) as ORDERID, TRADE_ORDERDETAIL.TRADEDATE, TRADE_ORDERDETAIL.ORDERPRICE,
  67. TRADE_ORDERDETAIL.ORDERQTY - TRADE_ORDERDETAIL.TRADEQTY - TRADE_ORDERDETAIL.CANCELQTY as ENABLEQTY,
  68. substr(USERACCOUNT.ACCOUNTNAME,0,1)||'****' as ACCOUNTNAME`).
  69. Where("TRADE_ORDERDETAIL.ORDERSTATUS in (3,7,12) and GOODS.GOODSID = ?", req.GoodsID)
  70. if len(req.AccountName) > 0 {
  71. s = s.And("USERACCOUNT.ACCOUNTNAME = ?", req.AccountName)
  72. }
  73. if req.MarketID > 0 {
  74. s = s.And("TRADE_ORDERDETAIL.MARKETID = ?", req.MarketID)
  75. }
  76. if req.BuyOrSell > -1 {
  77. s = s.And("TRADE_ORDERDETAIL.BUYORSELL = ?", req.BuyOrSell)
  78. }
  79. // 判断是否要分页
  80. // 这样分页会报错
  81. // if req.Size > 0 {
  82. // s = s.Limit(req.Size, req.Page*req.Size)
  83. // }
  84. d1 := make([]QueryRecieptOrderRsp, 0)
  85. if err := s.Find(&d1); err != nil {
  86. // 查询失败
  87. logger.GetLogger().Errorf("QueryRecieptOrder failed: %s", err.Error())
  88. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  89. return
  90. }
  91. datas = append(datas, d1...)
  92. // 报价商挂牌委托
  93. s = engine.Table("TRADE_QUOTEDETAILNEW").
  94. Join("INNER", "GOODS", "TRADE_QUOTEDETAILNEW.GOODSID = GOODS.GOODSID").
  95. Join("INNER", "QUOTER", "QUOTER.QUOTERID = TRADE_QUOTEDETAILNEW.QUOTERID").
  96. Join("INNER", "AREAROLE", "AREAROLE.USERID = QUOTER.DEFAULTMAKERID and AREAROLE.ROLETYPE = 8").
  97. Select(`GOODS.GOODSID, GOODS.GOODSCODE, GOODS.GOODSNAME,
  98. TRADE_QUOTEDETAILNEW.BUYORSELL, to_char(TRADE_QUOTEDETAILNEW.ORDERID) as ORDERID, TRADE_QUOTEDETAILNEW.TRADEDATE, TRADE_QUOTEDETAILNEW.PRICE as ORDERPRICE,
  99. TRADE_QUOTEDETAILNEW.CURQTY as ENABLEQTY,
  100. substr(QUOTER.QUOTERNAME,0,1)||'****' as ACCOUNTNAME`).
  101. Where("(TRADE_QUOTEDETAILNEW.CURQTY > 0 or TRADE_QUOTEDETAILNEW.PRICE > 0) and TRADE_QUOTEDETAILNEW.ISVALID != 1 and TRADE_QUOTEDETAILNEW.FREEZESTATUS != 3")
  102. d2 := make([]QueryRecieptOrderRsp, 0)
  103. if err := s.Find(&d2); err != nil {
  104. // 查询失败
  105. logger.GetLogger().Errorf("QueryRecieptOrder failed: %s", err.Error())
  106. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  107. return
  108. }
  109. datas = append(datas, d2...)
  110. total := len(datas)
  111. // FIXME: - 排序 & 分页
  112. // 排序
  113. sort.Slice(datas, func(i int, j int) bool {
  114. return datas[i].Tradedate > datas[j].Tradedate
  115. })
  116. // 分页
  117. if req.PageSize > 0 {
  118. // 开始上标
  119. start := req.Page * req.PageSize
  120. // 结束下标
  121. // a := []int{1,2,3,4,5}
  122. // a[2:4] -> [3 4]
  123. end := start + req.PageSize
  124. if start <= len(datas) {
  125. // 判断结束下标是否越界
  126. if end > len(datas) {
  127. end = len(datas)
  128. }
  129. datas = datas[start:end]
  130. } else {
  131. datas = make([]QueryRecieptOrderRsp, 0)
  132. }
  133. }
  134. // 查询成功返回
  135. logger.GetLogger().Infof("QueryRecieptOrder successed: %v", datas)
  136. if req.PageSize > 0 {
  137. // 分页
  138. appG.ResponseByPage(http.StatusOK, e.SUCCESS, datas, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  139. } else {
  140. // 不分页
  141. appG.Response(http.StatusOK, e.SUCCESS, datas)
  142. }
  143. }
  144. // QueryGoodsPickupReq 商品提货单查询请求参数
  145. type QueryGoodsPickupReq struct {
  146. AccountID string `form:"accountID" binding:"required"`
  147. TakeOrderStatus int `form:"takeOrderStatus"`
  148. }
  149. // QueryGoodsPickupRsp 商品提货单查询返回模型
  150. type QueryGoodsPickupRsp struct {
  151. models.Szdz3goodspickup `xorm:"extends"`
  152. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  153. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  154. }
  155. // QueryGoodsPickup 商品提货单查询
  156. // @Summary 商品提货单查询
  157. // @Produce json
  158. // @Security ApiKeyAuth
  159. // @Param accountID query string true "资金账户 - 格式:1,2,3"
  160. // @Param takeOrderStatus query int false "提货状态 - 1:待发货 2:已发货 3:已收货"
  161. // @Success 200 {object} QueryGoodsPickupRsp
  162. // @Failure 500 {object} app.Response
  163. // @Router /SZDZ/QueryGoodsPickup [get]
  164. // @Tags 定制【尚志大宗】
  165. func QueryGoodsPickup(c *gin.Context) {
  166. appG := app.Gin{C: c}
  167. // 获取请求参数
  168. var req QueryGoodsPickupReq
  169. if err := appG.C.ShouldBindQuery(&req); err != nil {
  170. logger.GetLogger().Errorf("QueryGoodsPickup failed: %s", err.Error())
  171. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  172. return
  173. }
  174. datas := make([]QueryGoodsPickupRsp, 0)
  175. engine := db.GetEngine()
  176. s := engine.Join("INNER", "GOODS", "GOODS.GOODSID = SZDZ3_GOODSPICKUP.GOODSID").
  177. Select("to_char(SZDZ3_GOODSPICKUP.TAKEORDERID) as TAKEORDERID, SZDZ3_GOODSPICKUP.*, GOODS.GOODSCODE, GOODS.GOODSNAME").
  178. Where(fmt.Sprintf(`SZDZ3_GOODSPICKUP.ACCOUNTID in (%s)`, req.AccountID)).
  179. Desc("SZDZ3_GOODSPICKUP.TAKEORDERID")
  180. if req.TakeOrderStatus > 0 {
  181. s = s.And("SZDZ3_GOODSPICKUP.TAKEORDERSTATUS = ?", req.TakeOrderStatus)
  182. }
  183. if err := s.Find(&datas); err != nil {
  184. // 查询失败
  185. logger.GetLogger().Errorf("QueryGoodsPickup failed: %s", err.Error())
  186. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  187. return
  188. }
  189. // 查询成功返回
  190. logger.GetLogger().Infof("QueryGoodsPickup successed: %v", datas)
  191. appG.Response(http.StatusOK, e.SUCCESS, datas)
  192. }
  193. // QueryConvertLogReq 交易系统转换流水查询请求参数
  194. type QueryConvertLogReq struct {
  195. AccountID string `form:"accountID" binding:"required"`
  196. StartDate string `form:"startDate"`
  197. EndDate string `form:"endDate"`
  198. }
  199. // QueryConvertLogRsp 交易系统转换流水查询返回模型
  200. type QueryConvertLogRsp struct {
  201. models.Szdz3convertlog `xorm:"extends"`
  202. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  203. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  204. QTY string `json:"qty"` // 数量
  205. }
  206. // QueryConvertLog 交易系统转换流水查询
  207. // @Summary 交易系统转换流水查询
  208. // @Produce json
  209. // @Security ApiKeyAuth
  210. // @Param accountID query string true "资金账户 - 格式:1,2,3"
  211. // @Param startDate query string false "开始时间 - 闭区间,格式:yyyy-MM-dd HH:mm:ss"
  212. // @Param endDate query string false "结束时间 - 闭区间,格式:yyyy-MM-dd HH:mm:ss"
  213. // @Success 200 {object} QueryConvertLogRsp
  214. // @Failure 500 {object} app.Response
  215. // @Router /SZDZ/QueryConvertLog [get]
  216. // @Tags 定制【尚志大宗】
  217. func QueryConvertLog(c *gin.Context) {
  218. appG := app.Gin{C: c}
  219. // 获取请求参数
  220. var req QueryConvertLogReq
  221. if err := appG.C.ShouldBindQuery(&req); err != nil {
  222. logger.GetLogger().Errorf("QueryConvertLog failed: %s", err.Error())
  223. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  224. return
  225. }
  226. datas := make([]QueryConvertLogRsp, 0)
  227. engine := db.GetEngine()
  228. s := engine.Join("INNER", "GOODS", "GOODS.GOODSID = SZDZ3_CONVERTLOG.INNERGOODSID").
  229. Select("SZDZ3_CONVERTLOG.*, GOODS.GOODSCODE, GOODS.GOODSNAME").
  230. Where(fmt.Sprintf(`SZDZ3_CONVERTLOG.HandleStatus = 1 and SZDZ3_CONVERTLOG.ACCOUNTID in (%s)`, req.AccountID)).
  231. Desc("SZDZ3_CONVERTLOG.LOGID")
  232. if len(req.StartDate) > 0 {
  233. s = s.And(fmt.Sprintf(`SZDZ3_CONVERTLOG.CREATETIME >= to_date('%s','yyyy-MM-dd hh24:mi:ss')`, req.StartDate))
  234. }
  235. if len(req.EndDate) > 0 {
  236. s = s.And(fmt.Sprintf(`SZDZ3_CONVERTLOG.CREATETIME <= to_date('%s','yyyy-MM-dd hh24:mi:ss')`, req.EndDate))
  237. }
  238. if err := s.Find(&datas); err != nil {
  239. // 查询失败
  240. logger.GetLogger().Errorf("QueryConvertLog failed: %s", err.Error())
  241. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  242. return
  243. }
  244. // 计算数量
  245. for i, v := range datas {
  246. queryConvertLog := &datas[i]
  247. // 方向
  248. direction := "-"
  249. // 数量
  250. qty := v.Outvalue
  251. if v.Converttype == 1 || v.Converttype == 2 {
  252. direction = "+"
  253. qty = v.Invalue
  254. }
  255. queryConvertLog.QTY = fmt.Sprintf("%s%v", direction, qty)
  256. }
  257. // 查询成功返回
  258. logger.GetLogger().Infof("QueryConvertLog successed: %v", datas)
  259. appG.Response(http.StatusOK, e.SUCCESS, datas)
  260. }
  261. // SearchWhiteReq 搜索白名单请求参数
  262. type SearchWhiteReq struct {
  263. UserID int `form:"userID" binding:"required"`
  264. }
  265. // SearchWhite 搜索白名单
  266. // @Summary 搜索白名单
  267. // @Produce json
  268. // @Security ApiKeyAuth
  269. // @Param userID query int true "用户ID"
  270. // @Success 200 {object} models.Szdz3searchwhitelist
  271. // @Failure 500 {object} app.Response
  272. // @Router /SZDZ/SearchWhite [get]
  273. // @Tags 定制【尚志大宗】
  274. func SearchWhite(c *gin.Context) {
  275. appG := app.Gin{C: c}
  276. // 获取请求参数
  277. var req SearchWhiteReq
  278. if err := appG.C.ShouldBindQuery(&req); err != nil {
  279. logger.GetLogger().Errorf("SearchWhite failed: %s", err.Error())
  280. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  281. return
  282. }
  283. datas := make([]models.Szdz3searchwhitelist, 0)
  284. engine := db.GetEngine()
  285. if err := engine.Where("USERID = ?", req.UserID).Find(&datas); err != nil {
  286. // 查询失败
  287. logger.GetLogger().Errorf("SearchWhite failed: %s", err.Error())
  288. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  289. return
  290. }
  291. // 查询成功返回
  292. logger.GetLogger().Infof("SearchWhite successed: %v", datas)
  293. appG.Response(http.StatusOK, e.SUCCESS, datas)
  294. }
  295. // QueryConvertConfigReq 查询交易系统转换设置请求参数
  296. type QueryConvertConfigReq struct {
  297. ConvertType int `form:"convertType"` // 转换类型 - 1:金点赞转交易 2:金点拍转交易
  298. OuterGoodsCode string `form:"outerGoodsCode"` // 外部商品代码[JD\PD]
  299. InnerGoodsIDs string `form:"innerGoodsIDs"` // 内部商品ID列表[交易]
  300. }
  301. // QueryConvertConfig 查询交易系统转换设置
  302. // @Summary 查询交易系统转换设置
  303. // @Produce json
  304. // @Security ApiKeyAuth
  305. // @Param convertType query int false "转换类型 - 1:金点赞转交易 2:金点拍转交易"
  306. // @Param outerGoodsCode query string false "外部商品代码[JD\PD]"
  307. // @Param innerGoodsIDs query string false "内部商品ID列表[交易],格式:1,2,3"
  308. // @Success 200 {object} models.Szdz3convertconfig
  309. // @Failure 500 {object} app.Response
  310. // @Router /SZDZ/QueryConvertConfig [get]
  311. // @Tags 定制【尚志大宗】
  312. func QueryConvertConfig(c *gin.Context) {
  313. appG := app.Gin{C: c}
  314. // 获取请求参数
  315. var req QueryConvertConfigReq
  316. if err := appG.C.ShouldBindQuery(&req); err != nil {
  317. logger.GetLogger().Errorf("QueryConvertConfigReq failed: %s", err.Error())
  318. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  319. return
  320. }
  321. datas := make([]models.Szdz3convertconfig, 0)
  322. engine := db.GetEngine()
  323. s := engine.Table("SZDZ3_CONVERTCONFIG")
  324. if req.ConvertType > 0 {
  325. s = s.And("CONVERTTYPE = ?", req.ConvertType)
  326. }
  327. if len(req.OuterGoodsCode) > 0 {
  328. s = s.And("OUTERGOODSCODE = ?", req.OuterGoodsCode)
  329. }
  330. if len(req.InnerGoodsIDs) > 0 {
  331. s = s.And(fmt.Sprintf("INNERGOODSID in (%s)", req.InnerGoodsIDs))
  332. }
  333. if err := s.Find(&datas); err != nil {
  334. // 查询失败
  335. logger.GetLogger().Errorf("QueryConvertConfigReq failed: %s", err.Error())
  336. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  337. return
  338. }
  339. // 查询成功返回
  340. logger.GetLogger().Infof("QueryConvertConfigReq successed: %v", datas)
  341. appG.Response(http.StatusOK, e.SUCCESS, datas)
  342. }