wrTrade2.go 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/7/20 18:31
  4. * @Modify : 2021/7/20 18:31
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/utils"
  11. "strings"
  12. )
  13. // WrOrderQuote 买卖大厅行情
  14. type WrOrderQuote struct {
  15. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'" form:"wrfactortypeid"` // 仓单要素id
  16. BUYPRICE float64 `json:"buyprice" xorm:"'BUYPRICE'"` // 买价
  17. BUYQTY float64 `json:"buyqty" xorm:"'BUYQTY'"` // 买量
  18. SELLPRICE float64 `json:"sellprice" xorm:"'SELLPRICE'"` // 卖价
  19. SELLQTY float64 `json:"sellqty" xorm:"'SELLQTY'"` // 卖量
  20. WRFACTORTYPENAME string `json:"wrfactortypename" xorm:"'WRFACTORTYPENAME'"` // 仓单要素类型名称(选择项要素的名称合并显示,逗号分隔)
  21. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种id
  22. WRSTANDARDID int32 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 商品id
  23. WAREHOUSEID int32 `json:"warehouseid" xorm:"'WAREHOUSEID'" form:"warehouseid"` // 仓库id
  24. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  25. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  26. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  27. WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码
  28. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'" form:"wrstandardname"` // 商品名称
  29. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 商品代码
  30. WRGOODSNAME string `json:"wrgoodsname" xorm:"'WRGOODSNAME'"` // 商品(商品名称+仓库要素名称 拼接)
  31. BUYPRICEMOVE float64 `json:"buypricemove" xorm:"'BUYPRICEMOVE'"` // 买升贴水(基差)
  32. SELLPRICEMOVE float64 `json:"sellpricemove" xorm:"'SELLPRICEMOVE'"` // 卖升贴水(基差)
  33. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'"` // 商品id(浮动价列表才有)
  34. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品合约(浮动价列表才有)
  35. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'"` // 交收月
  36. PageEx `xorm:"extends"` // 页码信息
  37. HasWr int32 `json:"-" form:"haswr"` // 是否有仓单 0-没有 1-有
  38. WrPriceType int32 `json:"-" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  39. MarketId int32 `json:"-" form:"marketid"` // 市场id
  40. BRANDNAME string `json:"-" form:"brandname"` // 品牌名称
  41. }
  42. func (r *WrOrderQuote) calc() {
  43. r.WRGOODSNAME = strings.ReplaceAll(r.WRGOODSNAME, ",", "-")
  44. }
  45. // buildSqlFixedPrice 一口价
  46. func (r *WrOrderQuote) buildSqlFixedPrice() string {
  47. var sqlId utils.SQLVal = "with buyQuote as" +
  48. " (" +
  49. " select a.wrfactortypeid, a.fixedprice buyPrice, sum(a.orderqty) buyQty" +
  50. " from (select t.wrfactortypeid," +
  51. " t.marketid," +
  52. " t.buyorsell," +
  53. " t.orderqty - t.tradeqty as orderqty," +
  54. " t.fixedprice," +
  55. " rank() over(partition by t.wrfactortypeid order by t.fixedprice desc) cnt" +
  56. " from wrtrade_orderdetail t" +
  57. " where t.wrtradetype = 1 and t.buyorsell = 0 and t.wrtradeorderstatus in(3,10) %v" +
  58. " ) a" +
  59. " where a.cnt = 1" +
  60. " group by a.wrfactortypeid, a.fixedprice)," +
  61. "sellQuote as" +
  62. " (" +
  63. " select a.wrfactortypeid, a.fixedprice sellPrice, sum(a.orderqty) sellQty" +
  64. " from (select t.wrfactortypeid," +
  65. " t.marketid," +
  66. " t.buyorsell," +
  67. " t.orderqty - t.tradeqty as orderqty," +
  68. " t.fixedprice," +
  69. " rank() over(partition by t.wrfactortypeid order by t.fixedprice asc) cnt" +
  70. " from wrtrade_orderdetail t" +
  71. " where t.wrtradetype = 1 and t.buyorsell = 1 and t.wrtradeorderstatus in(3,10) %v " +
  72. " ) a" +
  73. " where a.cnt = 1" +
  74. " group by a.wrfactortypeid, a.fixedprice)," +
  75. "wrQuote as (" +
  76. " select nvl(k1.wrfactortypeid, k2.wrfactortypeid) wrfactortypeid," +
  77. " k1.buyPrice," +
  78. " k1.buyQty," +
  79. " k2.sellPrice," +
  80. " k2.sellQty" +
  81. " from buyQuote k1" +
  82. " full join sellQuote k2" +
  83. " on k1.wrfactortypeid = k2.wrfactortypeid" +
  84. ")" +
  85. "select k.*," +
  86. " w.wrfactortypename," +
  87. " w.deliverygoodsid," +
  88. " w.wrstandardid," +
  89. " w.warehouseid," +
  90. " dg.deliverygoodsname," +
  91. " dg.deliverygoodscode," +
  92. " h.warehousename," +
  93. " h.warehousecode," +
  94. " wg.wrstandardname," +
  95. " wg.wrstandardcode," +
  96. " wg.wrstandardname || w.wrfactortypename as wrgoodsname" +
  97. " from wrQuote k" +
  98. " left join WRFactorType w" +
  99. " on k.wrfactortypeid = w.wrfactortypeid" +
  100. " left join deliverygoods dg" +
  101. " on w.deliverygoodsid = dg.deliverygoodsid" +
  102. " left join wrstandard wg" +
  103. " on w.wrstandardid = wg.wrstandardid" +
  104. " left join warehouseinfo h" +
  105. " on w.warehouseid = h.autoid" +
  106. " where 1=1 %v " +
  107. "order by deliverygoodsname"
  108. var param, param2 utils.SQLVal
  109. param.And("t.haswr", r.HasWr)
  110. param.And("t.wrpricetype", r.WrPriceType)
  111. param.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  112. param2.AndLike("w.wrfactortypename", r.WRSTANDARDNAME)
  113. param2.AndLike("w.wrfactortypename", r.BRANDNAME)
  114. param2.AndEx("w.warehouseid", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  115. sqlId.FormatParam(param.String(), param.String(), param2.String())
  116. sqlId.Page(r.Page, r.PageSize)
  117. return sqlId.String()
  118. }
  119. // buildSqlPriceMove 浮动价
  120. func (r *WrOrderQuote) buildSqlPriceMove() string {
  121. var sqlId utils.SQLVal = "with buyQuote as" +
  122. " (select a.wrfactortypeid," +
  123. " a.pricemove buypricemove," +
  124. " sum(a.orderqty) buyQty," +
  125. " a.goodsid," +
  126. " a.goodscode," +
  127. " a.deliverymonth" +
  128. " from (select t.wrfactortypeid," +
  129. " t.marketid," +
  130. " t.buyorsell," +
  131. " t.orderqty - t.tradeqty as orderqty," +
  132. " t.pricemove," +
  133. " t.wrtradeorderid," +
  134. " t.deliverymonth," +
  135. " c.goodsid," +
  136. " c.goodscode," +
  137. " rank() over(partition by t.wrfactortypeid, nvl(t.deliverymonth,'0'), c.goodsid order by t.pricemove desc) cnt" +
  138. " from wrtrade_orderdetail t" +
  139. " left join WRTrade_GoodsConfig c" +
  140. " on t.wrtradeorderid = c.wrtradeorderid" +
  141. " where t.wrtradetype = 1 and t.wrtradeorderstatus in(3,10)" +
  142. " and t.buyorsell = 0 %v) a" +
  143. " where a.cnt = 1" +
  144. " group by a.wrfactortypeid, a.pricemove, a.goodsid, a.goodscode, a.deliverymonth)," +
  145. "sellQuote as" +
  146. " (select a.wrfactortypeid," +
  147. " a.pricemove sellpricemove," +
  148. " a.goodsid," +
  149. " a.goodscode," +
  150. " a.deliverymonth," +
  151. " sum(a.orderqty) sellQty" +
  152. " from (select t.wrfactortypeid," +
  153. " t.marketid," +
  154. " t.buyorsell," +
  155. " t.orderqty - t.tradeqty as orderqty," +
  156. " t.pricemove," +
  157. " t.deliverymonth," +
  158. " c.goodsid," +
  159. " c.goodscode," +
  160. " rank() over(partition by t.wrfactortypeid, nvl(t.deliverymonth,'0'), c.goodsid order by t.pricemove asc) cnt" +
  161. " from wrtrade_orderdetail t" +
  162. " left join WRTrade_GoodsConfig c" +
  163. " on t.wrtradeorderid = c.wrtradeorderid" +
  164. " where t.wrtradetype = 1 and t.wrtradeorderstatus in(3,10)" +
  165. " and t.buyorsell = 1 %v) a" +
  166. " where a.cnt = 1" +
  167. " group by a.wrfactortypeid, a.pricemove, a.goodsid, a.goodscode, a.deliverymonth)," +
  168. "wrQuote as" +
  169. " (select nvl(k1.wrfactortypeid, k2.wrfactortypeid) wrfactortypeid," +
  170. " nvl(k1.goodsid, k2.goodsid) goodsid," +
  171. " nvl(k1.goodscode, k2.goodscode) goodscode," +
  172. " nvl(k1.deliverymonth, k2.deliverymonth) deliverymonth," +
  173. " k1.buypricemove," +
  174. " k1.buyQty," +
  175. " k2.sellpricemove," +
  176. " k2.sellQty" +
  177. " from buyQuote k1" +
  178. " full join sellQuote k2" +
  179. " on k1.wrfactortypeid = k2.wrfactortypeid and k1.deliverymonth = k2.deliverymonth)" +
  180. "select k.*," +
  181. " w.wrfactortypename," +
  182. " w.deliverygoodsid," +
  183. " w.wrstandardid," +
  184. " w.warehouseid," +
  185. " dg.deliverygoodsname," +
  186. " dg.deliverygoodscode," +
  187. " h.warehousename," +
  188. " h.warehousecode," +
  189. " wg.wrstandardname," +
  190. " wg.wrstandardcode," +
  191. " wg.wrstandardname || w.wrfactortypename as wrgoodsname" +
  192. " from wrQuote k" +
  193. " left join WRFactorType w" +
  194. " on k.wrfactortypeid = w.wrfactortypeid" +
  195. " left join deliverygoods dg" +
  196. " on w.deliverygoodsid = dg.deliverygoodsid" +
  197. " left join wrstandard wg" +
  198. " on w.wrstandardid = wg.wrstandardid" +
  199. " left join warehouseinfo h" +
  200. " on w.warehouseid = h.autoid" +
  201. " where 1 = 1 %v" +
  202. " order by deliverygoodsname"
  203. var param, param2 utils.SQLVal
  204. param.And("t.haswr", r.HasWr)
  205. param.And("t.wrpricetype", r.WrPriceType)
  206. param.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  207. param2.AndLike("w.wrfactortypename", r.WRSTANDARDNAME)
  208. param2.AndLike("w.wrfactortypename", r.BRANDNAME)
  209. param2.AndEx("w.warehouseid", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  210. sqlId.FormatParam(param.String(), param.String(), param2.String())
  211. sqlId.Page(r.Page, r.PageSize)
  212. return sqlId.String()
  213. }
  214. func (r *WrOrderQuote) buildSql() string {
  215. if r.WrPriceType == 1 {
  216. return r.buildSqlFixedPrice()
  217. } else {
  218. return r.buildSqlPriceMove()
  219. }
  220. }
  221. // GetDataByPage 获取买卖大厅行情
  222. func (r *WrOrderQuote) GetDataByPage() (interface{}, error, int, int, int) {
  223. sData := make([]WrOrderQuote, 0)
  224. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  225. total := 0
  226. for i := range sData {
  227. sData[i].calc()
  228. total = sData[i].Total
  229. }
  230. return sData, err, r.Page, r.PageSize, total
  231. }
  232. // WrOrderQuoteDetail 行情大厅明细(买卖大厅)
  233. type WrOrderQuoteDetail struct {
  234. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  235. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖
  236. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 购买方(销售方)用户ID
  237. QTY float64 `json:"orderqty" xorm:"ORDERQTY"` // 买(卖)量(=委托量-成交量)
  238. PRICE float64 `json:"fixedprice" xorm:"FIXEDPRICE"` // 买(卖)价
  239. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE"` // 买(卖)升贴水- 基差
  240. USERNAME string `json:"username" xorm:"'USERNAME'"` // 购买方(销售方)
  241. PageEx `xorm:"extends"`
  242. WRFACTORTYPEID int64 `json:"-" form:"wrfactortypeid"` // 仓单要素id
  243. HasWr int32 `json:"-" form:"haswr"` // 是否有仓单 0-没有 1-有
  244. WrPriceType int32 `json:"-" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  245. MarketId int32 `json:"-" form:"marketid"` // 市场id
  246. GOODSID int32 `json:"-" form:"goodsid"` // 商品id
  247. }
  248. func (r *WrOrderQuoteDetail) calc() {
  249. }
  250. func (r *WrOrderQuoteDetail) buildSql() string {
  251. var sqlId utils.SQLVal = "select t.wrtradeorderid," +
  252. " t.wrfactortypeid," +
  253. " t.userid," +
  254. " t.orderqty - t.tradeqty as qty," +
  255. " t.fixedprice as price," +
  256. " t.pricemove," +
  257. " t.wrpricetype," +
  258. " t.buyorsell," +
  259. " u.accountname as username," +
  260. " c.goodsid," +
  261. " c.goodscode" +
  262. " from WRTRADE_ORDERDETAIL t" +
  263. " left join WRTRADE_GOODSCONFIG c" +
  264. " on t.wrtradeorderid = c.wrtradeorderid" +
  265. " left join Useraccount u" +
  266. " on t.userid = u.Accountname" +
  267. " where 1 = 1" +
  268. " and t.wrtradetype = 1" +
  269. " and t.wrtradeorderstatus in (3, 10)"
  270. sqlId.And("t.haswr", r.HasWr)
  271. sqlId.And("t.wrpricetype", r.WrPriceType)
  272. sqlId.And("t.wrfactortypeid", r.WRFACTORTYPEID)
  273. sqlId.And("c.goodsid", r.GOODSID)
  274. sqlId.And("t.buyorsell", r.BUYORSELL)
  275. sqlId.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  276. if r.BUYORSELL == 0 {
  277. if r.WrPriceType == 1 {
  278. sqlId.Join(" order by t.fixedprice desc")
  279. } else {
  280. sqlId.Join(" order by t.pricemove desc")
  281. }
  282. } else {
  283. if r.WrPriceType == 1 {
  284. sqlId.Join(" order by t.fixedprice asc")
  285. } else {
  286. sqlId.Join(" order by t.pricemove asc")
  287. }
  288. }
  289. sqlId.Page(r.Page, r.PageSize)
  290. return sqlId.String()
  291. }
  292. // GetDataByPage 获取行情大厅明细(买卖大厅)
  293. func (r *WrOrderQuoteDetail) GetDataByPage() (interface{}, error, int, int, int) {
  294. sData := make([]WrOrderQuoteDetail, 0)
  295. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  296. total := 0
  297. for i := range sData {
  298. sData[i].calc()
  299. total = sData[i].Total
  300. }
  301. return sData, err, r.Page, r.PageSize, total
  302. }
  303. // Wr2FactorType 仓单要素类型
  304. type Wr2FactorType struct {
  305. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)
  306. WRFACTORTYPENAME string `json:"wrfactortypename" xorm:"WRFACTORTYPENAME" form:"wrfactortypename"` // 仓单要素类型名称(选择项要素的名称合并显示,逗号分隔)
  307. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 品种ID
  308. WAREHOUSEID int64 `json:"warehouseid" xorm:"WAREHOUSEID" form:"warehouseid"` // 仓库ID
  309. WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID" form:"wrstandardid"` // 现货商品ID
  310. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE" form:"wrstandardcode"` // 现货商品代码
  311. OPTIONCOMPARE string `json:"optioncompare" xorm:"OPTIONCOMPARE" form:"optioncompare"` // 选择项比较串【{选择项ID}+{冒号}+选择项值 } ,逗号分隔,头尾加逗号】-- 所有选择项拼接,用于比较
  312. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 商品名称
  313. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  314. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  315. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  316. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  317. WRTYPENAME string `json:"wrtypename"` // 商品
  318. }
  319. func (r *Wr2FactorType) Calc() {
  320. r.WRTYPENAME = r.WRSTANDARDNAME + "-" + r.WRFACTORTYPENAME
  321. r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
  322. }
  323. // WrPosition 仓单贸易持仓汇总
  324. type WrPosition struct {
  325. WRPOSITIONID int64 `json:"wrpositionid" xorm:"WRPOSITIONID" form:"wrpositionid"` // 仓单头寸ID(201+Unix秒时间戳(10位)+xxxxxx)
  326. WRUSERID int64 `json:"wruserid" xorm:"WRUSERID" form:"userid"` // 持有人ID
  327. TOTALQTY float64 `json:"totalqty" xorm:"TOTALQTY" form:"totalqty"` // 总数量(库存数量)
  328. INCREASEQTY float64 `json:"-" xorm:"INCREASEQTY" form:"increaseqty"` // 今日增加数量
  329. DECREASEQTY float64 `json:"-" xorm:"DECREASEQTY" form:"decreaseqty"` // 今日减少数量
  330. FREEZEQTY float64 `json:"freezeqty" xorm:"FREEZEQTY" form:"freezeqty"` // 总冻结数量
  331. RELATEDQTY float64 `json:"-" xorm:"RELATEDQTY" form:"relatedqty"` // 关联数量
  332. MODIFYTIME string `json:"modifytime" xorm:"MODIFYTIME" form:"modifytime"` // 修改时间(过户时间)
  333. MODIFIERID int64 `json:"-" xorm:"MODIFIERID" form:"modifierid"` // 修改人
  334. TRADEWRQTY float64 `json:"-" xorm:"TRADEWRQTY" form:"tradewrqty"` // 订单仓单头寸总数量
  335. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid"` // 帐户ID
  336. CREDITTOTALQTY float64 `json:"credittotalqty" xorm:"CREDITTOTALQTY" form:"credittotalqty"` // 授信总数量(预售仓单:预售总量)
  337. CREDITCURQTY float64 `json:"creditcurqty" xorm:"CREDITCURQTY" form:"creditcurqty"` // 授信当前数量(预售仓单:预售当前量)
  338. CREDITFREEZEQTY float64 `json:"creditfreezeqty" xorm:"CREDITFREEZEQTY" form:"creditfreezeqty"` // 授信冻结数量(预售仓单: 当前数量)
  339. CREDITTRADEQTY float64 `json:"credittradeqty" xorm:"CREDITTRADEQTY" form:"credittradeqty"` // 授信成交数量(预售仓单:成交总量)
  340. Wr2FactorType `xorm:"extends"`
  341. ENALBEQTY float64 `json:"enalbeqty" xorm:"'ENALBEQTY'"` // 可用数量
  342. CREDITENABLEQTY float64 `json:"creditenableqty" xorm:"'CREDITENABLEQTY'"` // 授信可用数量(预售仓单: 可用数量)
  343. PLEDGEQTY float64 `json:"pledgeqty" xorm:"'-'"` // 质押数量
  344. BUYEXCUTEQTY float64 `json:"buyexcuteqty"` // 采购履约中数量
  345. SELLEXCUTEQTY float64 `json:"sellexcuteqty"` // 销售履约中数量
  346. WRPOSITIONNO string `json:"wrpositionno"` // 仓单编号
  347. QueryType int32 `json:"querytype" form:"querytype"` // 查询类型 1-现货汇总 2-库存汇总(订单汇总) 3-现货明细
  348. }
  349. func (r *WrPosition) calc() {
  350. r.ENALBEQTY = r.TOTALQTY - r.FREEZEQTY
  351. r.CREDITENABLEQTY = r.CREDITCURQTY - r.CREDITFREEZEQTY
  352. r.WRPOSITIONNO = fmt.Sprintf("%v", r.WRFACTORTYPEID)
  353. r.Wr2FactorType.Calc()
  354. }
  355. func (r *WrPosition) buildSql() string {
  356. if r.QueryType == 1 {
  357. // 现货汇总 品种 + 品类 + 其它要素, 根据品种汇总
  358. return r.buildSql1()
  359. } else if r.QueryType == 2 {
  360. // 库存汇总 品种 + 仓库 + 品类 + 其它要素, 即全维度
  361. return r.buildSql2()
  362. } else {
  363. // 现货明细 仓单编号 + 品种 + 仓库 + 仓单要素 即全维度 跟库存汇总一样
  364. return r.buildSql3()
  365. }
  366. }
  367. func (r *WrPosition) buildSql1() string {
  368. var sqlId utils.SQLVal = "with tmp as" +
  369. " (select t.*," +
  370. " w.wrstandardid," +
  371. " w.warehouseid," +
  372. " wd.wrstandardname," +
  373. " wd.wrstandardname || '-' ||w.wrfactortypename as wrtypename" +
  374. " from WRPOSITION t" +
  375. " left join WRFACTORTYPE w" +
  376. " on t.wrfactortypeid = w.wrfactortypeid" +
  377. " left join wrstandard wd" +
  378. " on w.wrstandardid = wd.wrstandardid" +
  379. " where t.wruserid = %v)," +
  380. "hld as" +
  381. " (select k.deliverygoodsid," +
  382. " k.wrtypename," +
  383. " sum(k.TOTALQTY) TOTALQTY," +
  384. " sum(k.INCREASEQTY) INCREASEQTY," +
  385. " sum(k.DECREASEQTY) DECREASEQTY," +
  386. " sum(k.FREEZEQTY) FREEZEQTY," +
  387. " sum(k.RELATEDQTY) RELATEDQTY," +
  388. " sum(k.TRADEWRQTY) TRADEWRQTY," +
  389. " sum(k.CREDITTOTALQTY) CREDITTOTALQTY," +
  390. " sum(k.CREDITCURQTY) CREDITCURQTY," +
  391. " sum(k.CREDITFREEZEQTY) CREDITFREEZEQTY," +
  392. " sum(k.CREDITTRADEQTY) CREDITTRADEQTY" +
  393. " from tmp k" +
  394. " where 1 = 1" +
  395. " group by k.deliverygoodsid, k.wrstandardname, k.wrtypename)" +
  396. "select h.*, g.deliverygoodsname, g.deliverygoodscode, e.enumdicname" +
  397. " from hld h" +
  398. " left join deliverygoods g" +
  399. " on h.deliverygoodsid = g.deliverygoodsid" +
  400. " left join enumdicitem e" +
  401. " on e.enumitemname = g.goodsunitid" +
  402. " and e.enumdiccode = 'goodsunit'"
  403. sqlId.FormatParam(r.WRUSERID)
  404. return sqlId.String()
  405. }
  406. func (r *WrPosition) buildSql2() string {
  407. return r.buildSql3()
  408. }
  409. func (r *WrPosition) buildSql3() string {
  410. var sqlId utils.SQLVal = "SELECT t.WRPOSITIONID," +
  411. " t.WRUSERID," +
  412. " t.TOTALQTY," +
  413. " t.INCREASEQTY," +
  414. " t.DECREASEQTY," +
  415. " t.FREEZEQTY," +
  416. " t.RELATEDQTY," +
  417. " to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
  418. " t.MODIFIERID," +
  419. " t.TRADEWRQTY," +
  420. " t.ACCOUNTID," +
  421. " t.CREDITTOTALQTY," +
  422. " t.CREDITCURQTY," +
  423. " t.CREDITFREEZEQTY," +
  424. " t.CREDITTRADEQTY," +
  425. " w.WRFACTORTYPEID," +
  426. " w.WRFACTORTYPENAME," +
  427. " w.DELIVERYGOODSID," +
  428. " w.WAREHOUSEID," +
  429. " w.WRSTANDARDID," +
  430. " w.WRSTANDARDCODE," +
  431. " w.OPTIONCOMPARE," +
  432. " dg.deliverygoodscode," +
  433. " dg.deliverygoodsname," +
  434. " wd.wrstandardcode," +
  435. " wd.wrstandardname," +
  436. " e.enumdicname" +
  437. " FROM WRPOSITION t" +
  438. " LEFT JOIN WRFACTORTYPE w" +
  439. " on t.wrfactortypeid = w.wrfactortypeid" +
  440. " LEFT JOIN DELIVERYGOODS dg" +
  441. " on t.deliverygoodsid = dg.deliverygoodsid" +
  442. " LEFT JOIN WRSTANDARD wd" +
  443. " on w.wrstandardid = wd.wrstandardid" +
  444. " left join enumdicitem e" +
  445. " on e.enumitemname = dg.goodsunitid" +
  446. " and e.enumdiccode = 'goodsunit'" +
  447. " WHERE 1 = 1"
  448. sqlId.And("t.WRUSERID", r.WRUSERID)
  449. return sqlId.String()
  450. }
  451. // GetDataEx 获取仓单贸易持仓汇总
  452. func (r *WrPosition) GetDataEx() (interface{}, error) {
  453. sData := make([]WrPosition, 0)
  454. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  455. for i := range sData {
  456. sData[i].calc()
  457. sData[i].QueryType = r.QueryType
  458. }
  459. return sData, err
  460. }
  461. // WrOrderDetail 仓单贸易委托单
  462. type WrOrderDetail struct {
  463. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  464. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  465. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  466. WRTRADETYPE int32 `json:"wrtradetype" xorm:"WRTRADETYPE" form:"wrtradetype"` // 仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
  467. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
  468. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  469. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  470. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID/商品ID(77)
  471. ORDERQTY float64 `json:"orderqty" xorm:"ORDERQTY" form:"orderqty"` // 委托数量
  472. TRADEQTY float64 `json:"tradeqty" xorm:"TRADEQTY" form:"tradeqty"` // 成交数量
  473. CANCELQTY float64 `json:"cancelqty" xorm:"CANCELQTY" form:"cancelqty"` // 撤销数量
  474. WRPRICETYPE int32 `json:"wrpricetype" xorm:"WRPRICETYPE" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  475. FIXEDPRICE float64 `json:"fixedprice" xorm:"FIXEDPRICE" form:"fixedprice"` // 固定价格 - [挂牌]
  476. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE" form:"pricemove"` // 升贴水(浮动价时填写) - [挂牌]
  477. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格 - [摘牌] (浮动价 ((商品1价格*商品1价格系数+升贴水)* 商品1重量系数 + 商品2价格*商品2价格系数+商品2升贴水)* 商品2重量系数 ...)* 委托单价格系数 + 委托单升贴水)
  478. ORDERTIME string `json:"ordertime" xorm:"ORDERTIME" form:"ordertime"` // 委托时间(挂牌时间)
  479. WRTRADEORDERSTATUS int32 `json:"wrtradeorderstatus" xorm:"WRTRADEORDERSTATUS"` // 委托状态 - 1:委托请求 2:待冻结 3:委托成功 4:委托失败 5:配对成功 6:已撤 7:已成 8:成交失败 9:委托拒绝 10:挂牌部分成交 11:仓单生成失败 12:首付扣款失败 13:履约失败 14:撤单解冻贷款失败 15:部成部撤
  480. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'"` // 期货商品id
  481. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 期货合约
  482. FUTUPRICEMOVE float64 `json:"futupricemove" xorm:"'FUTUPRICEMOVE'"` // 期货升贴水
  483. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'"` // 交收月
  484. Wr2FactorType `xorm:"extends"`
  485. PageEx `xorm:"extends"`
  486. FUTUSHOW string `json:"futushow"` // 期货合约/升贴水
  487. }
  488. func (r *WrOrderDetail) calc() {
  489. if r.GOODSCODE == "" {
  490. r.FUTUSHOW = "-"
  491. } else {
  492. r.FUTUSHOW = fmt.Sprintf("%v//%.2f", r.GOODSCODE, r.FUTUPRICEMOVE)
  493. }
  494. }
  495. func (r *WrOrderDetail) buildSql() string {
  496. var sqlId utils.SQLVal = "with tmp as" +
  497. " (select t.wrfactortypeid," +
  498. " t.wrfactortypename," +
  499. " t.wrstandardid," +
  500. " t.deliverygoodsid," +
  501. " g.deliverygoodscode," +
  502. " g.deliverygoodsname," +
  503. " w.wrstandardcode," +
  504. " w.wrstandardname," +
  505. " h.warehousecode," +
  506. " h.warehousename," +
  507. " e.enumdicname," +
  508. " w.wrstandardname || '-' || t.wrfactortypename as wrtypename" +
  509. " from wrfactortype t" +
  510. " left join deliverygoods g" +
  511. " on t.deliverygoodsid = g.deliverygoodsid" +
  512. " left join wrstandard w" +
  513. " on t.wrstandardid = w.wrstandardid" +
  514. " left join warehouseinfo h" +
  515. " on t.warehouseid = h.autoid" +
  516. " left join enumdicitem e on w.unitid = e.enumitemname and e.enumdiccode='goodsunit')" +
  517. "select t.HASWR," +
  518. " to_char(t.WRTRADEORDERID) WRTRADEORDERID," +
  519. " t.TRADEDATE," +
  520. " t.DELIVERYMONTH," +
  521. " t.WRTRADETYPE," +
  522. " t.BUYORSELL," +
  523. " t.MARKETID," +
  524. " t.USERID," +
  525. " t.ORDERQTY," +
  526. " t.TRADEQTY," +
  527. " t.CANCELQTY," +
  528. " t.WRPRICETYPE," +
  529. " t.FIXEDPRICE," +
  530. " t.PRICEMOVE," +
  531. " t.TRADEPRICE," +
  532. " to_char(t.ORDERTIME,'yyyy-mm-dd hh24:mi:ss') ORDERTIME," +
  533. " t.WRTRADEORDERSTATUS," +
  534. " c.GOODSID," +
  535. " c.GOODSCODE," +
  536. " c.pricemove FUTUPRICEMOVE," +
  537. " k.*" +
  538. " from wrtrade_orderdetail t" +
  539. " left join wrtrade_goodsconfig c" +
  540. " on t.wrtradeorderid = c.wrtradeorderid" +
  541. " left join tmp k" +
  542. " on t.wrfactortypeid = k.wrfactortypeid" +
  543. " where t.WRTRADETYPE = 1 and t.isspecified=0"
  544. sqlId.And("t.USERID", r.USERID)
  545. sqlId.And("t.haswr", r.HASWR)
  546. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  547. sqlId.Join(" order by t.ORDERTIME desc")
  548. sqlId.Page(r.Page, r.PageSize)
  549. return sqlId.String()
  550. }
  551. // GetDataByPage 获取仓单贸易委托单
  552. func (r *WrOrderDetail) GetDataByPage() (interface{}, error, int, int, int) {
  553. sData := make([]WrOrderDetail, 0)
  554. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  555. total := 0
  556. for i := range sData {
  557. sData[i].calc()
  558. total = sData[i].Total
  559. }
  560. return sData, err, r.Page, r.PageSize, total
  561. }
  562. // WrTradeDetail 仓单贸易成交明细
  563. type WrTradeDetail struct {
  564. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  565. WRTRADEDETAILID string `json:"wrtradedetailid" xorm:"WRTRADEDETAILID"` // 仓单贸易成交单ID(321+Unix秒时间戳(10位)+xxxxxx)
  566. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  567. WRTRADETYPE int32 `json:"wrtradetype" xorm:"WRTRADETYPE" form:"wrtradetype"` // 仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
  568. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
  569. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  570. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  571. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID/商品ID(77)
  572. TRADEQTY float64 `json:"tradeqty" xorm:"TRADEQTY" form:"tradeqty"` // 成交数量
  573. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格
  574. TRADETIME string `json:"tradetime" xorm:"TRADETIME" form:"tradetime"` // 成交时间
  575. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'"` // 交收月
  576. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID"` // 资金账号
  577. MATCHACCOUNTID int64 `json:"matchaccountid" xorm:"MATCHACCOUNTID"` // 对手账号
  578. MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 对手方
  579. Wr2FactorType `xorm:"extends"`
  580. PageEx `xorm:"extends"`
  581. }
  582. func (r *WrTradeDetail) calc() {
  583. }
  584. func (r *WrTradeDetail) buildSql() string {
  585. var sqlId utils.SQLVal = "with tmp as" +
  586. " (select t.wrfactortypeid," +
  587. " t.wrfactortypename," +
  588. " t.wrstandardid," +
  589. " t.deliverygoodsid," +
  590. " g.deliverygoodscode," +
  591. " g.deliverygoodsname," +
  592. " w.wrstandardcode," +
  593. " w.wrstandardname," +
  594. " h.warehousecode," +
  595. " h.warehousename," +
  596. " e.enumdicname," +
  597. " w.wrstandardname || '-' || t.wrfactortypename as wrtypename" +
  598. " from wrfactortype t" +
  599. " left join deliverygoods g" +
  600. " on t.deliverygoodsid = g.deliverygoodsid" +
  601. " left join wrstandard w" +
  602. " on t.wrstandardid = w.wrstandardid" +
  603. " left join warehouseinfo h" +
  604. " on t.warehouseid = h.autoid" +
  605. " left join enumdicitem e on w.unitid = e.enumitemname and e.enumdiccode='goodsunit')" +
  606. "select t.HASWR," +
  607. " to_char(t.WRTRADEDETAILID) WRTRADEDETAILID," +
  608. " t.TRADEDATE," +
  609. " t.DELIVERYMONTH," +
  610. " t.WRTRADETYPE," +
  611. " t.BUYORSELL," +
  612. " t.MARKETID," +
  613. " t.TRADEQTY," +
  614. " t.TRADEPRICE," +
  615. " to_char(t.TRADETIME,'yyyy-mm-dd hh24:mi:ss') TRADETIME," +
  616. " u2.accountname matchusername," +
  617. " ta1.userid," +
  618. " k.*" +
  619. " from wrtrade_tradedetail t" +
  620. " left join tmp k" +
  621. " on t.wrfactortypeid = k.wrfactortypeid" +
  622. " left join taaccount ta1 on t.accountid=ta1.accountid" +
  623. " left join taaccount ta2 on t.matchaccountid=ta2.accountid" +
  624. " left join useraccount u2 on ta2.userid=u2.userid" +
  625. " where 1=1"
  626. sqlId.And("ta1.userid", r.USERID)
  627. sqlId.And("t.haswr", r.HASWR)
  628. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  629. sqlId.Join(" order by t.tradetime desc")
  630. sqlId.Page(r.Page, r.PageSize)
  631. return sqlId.String()
  632. }
  633. // GetDataByPage 获取仓单贸易成交明细
  634. func (r *WrTradeDetail) GetDataByPage() (interface{}, error, int, int, int) {
  635. sData := make([]WrTradeDetail, 0)
  636. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  637. total := 0
  638. for i := range sData {
  639. sData[i].calc()
  640. total = sData[i].Total
  641. }
  642. return sData, err, r.Page, r.PageSize, total
  643. }
  644. // WrSpecialMatchOrder 指定对手委托
  645. type WrSpecialMatchOrder struct {
  646. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  647. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  648. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  649. WRTRADETYPE int32 `json:"wrtradetype" xorm:"WRTRADETYPE" form:"wrtradetype"` // 仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
  650. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
  651. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  652. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  653. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID/商品ID(77)
  654. ORDERQTY float64 `json:"orderqty" xorm:"ORDERQTY" form:"orderqty"` // 委托数量
  655. TRADEQTY float64 `json:"tradeqty" xorm:"TRADEQTY" form:"tradeqty"` // 成交数量
  656. CANCELQTY float64 `json:"cancelqty" xorm:"CANCELQTY" form:"cancelqty"` // 撤销数量
  657. WRPRICETYPE int32 `json:"wrpricetype" xorm:"WRPRICETYPE" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  658. FIXEDPRICE float64 `json:"fixedprice" xorm:"FIXEDPRICE" form:"fixedprice"` // 固定价格(价格)
  659. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE" form:"pricemove"` // 升贴水(浮动价时填写) - [挂牌]
  660. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格
  661. ORDERTIME string `json:"ordertime" xorm:"ORDERTIME" form:"ordertime"` // 委托时间
  662. WRTRADEORDERSTATUS int32 `json:"wrtradeorderstatus" xorm:"WRTRADEORDERSTATUS"` // 委托状态 - 1:委托请求 2:待冻结 3:委托成功 4:委托失败 5:配对成功 6:已撤 7:已成 8:成交失败 9:委托拒绝 10:挂牌部分成交 11:仓单生成失败 12:首付扣款失败 13:履约失败 14:撤单解冻贷款失败 15:部成部撤
  663. USERNAME string `json:"username" xorm:"'USERNAME'"` // 发起方
  664. MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 指定方
  665. MATCHUSERID int64 `json:"matchuserid" xorm:"'MATCHUSERID'"` // 指定方资金账号(字段名为userid,实际存的是accountid by:邓工)
  666. Wr2FactorType `xorm:"extends"`
  667. PageEx `xorm:"extends"`
  668. AMOUNT float64 `json:"amount"` // 金额 = 数量 * 价格
  669. }
  670. func (r *WrSpecialMatchOrder) calc() {
  671. r.AMOUNT = r.FIXEDPRICE * r.ORDERQTY
  672. }
  673. func (r *WrSpecialMatchOrder) buildSql() string {
  674. var sqlId utils.SQLVal = "with tmp as" +
  675. " (select t.wrfactortypeid," +
  676. " t.wrfactortypename," +
  677. " t.wrstandardid," +
  678. " t.deliverygoodsid," +
  679. " g.deliverygoodscode," +
  680. " g.deliverygoodsname," +
  681. " w.wrstandardcode," +
  682. " w.wrstandardname," +
  683. " h.warehousecode," +
  684. " h.warehousename," +
  685. " e.enumdicname," +
  686. " w.wrstandardname || '-' || t.wrfactortypename as wrtypename" +
  687. " from wrfactortype t" +
  688. " left join deliverygoods g" +
  689. " on t.deliverygoodsid = g.deliverygoodsid" +
  690. " left join wrstandard w" +
  691. " on t.wrstandardid = w.wrstandardid" +
  692. " left join warehouseinfo h" +
  693. " on t.warehouseid = h.autoid" +
  694. " left join enumdicitem e" +
  695. " on w.unitid = e.enumitemname" +
  696. " and e.enumdiccode = 'goodsunit')" +
  697. "select t.HASWR," +
  698. " to_char(t.WRTRADEORDERID) WRTRADEORDERID," +
  699. " t.WRTRADETYPE," +
  700. " t.BUYORSELL," +
  701. " t.MARKETID," +
  702. " t.USERID," +
  703. " t.ORDERQTY," +
  704. " t.TRADEQTY," +
  705. " t.CANCELQTY," +
  706. " t.WRPRICETYPE," +
  707. " t.FIXEDPRICE," +
  708. " t.PRICEMOVE," +
  709. " t.TRADEPRICE," +
  710. " to_char(t.ORDERTIME, 'yyyy-mm-dd hh24:mi:ss') ORDERTIME," +
  711. " t.WRTRADEORDERSTATUS," +
  712. " m.matchuserid," +
  713. " u1.accountname username," +
  714. " u2.accountname matchusername," +
  715. " k.*" +
  716. " from wrtrade_orderdetail t" +
  717. " left join WRTrade_MatchDetail m on t.wrtradeorderid=m.wrtradeorderid" +
  718. " left join useraccount u1 on t.userid=u1.userid" +
  719. " left join taaccount ta2 on m.matchuserid=ta2.accountid" +
  720. " left join useraccount u2 on ta2.userid=u2.userid" +
  721. " left join tmp k" +
  722. " on t.wrfactortypeid = k.wrfactortypeid" +
  723. " where t.WRTRADETYPE = 1" +
  724. " and t.isspecified = 1" +
  725. " and t.WRTRADEORDERSTATUS = 3"
  726. sqlId.And("t.USERID", r.USERID)
  727. sqlId.And("t.haswr", r.HASWR)
  728. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  729. sqlId.Join(" order by t.ORDERTIME desc")
  730. sqlId.Page(r.Page, r.PageSize)
  731. return sqlId.String()
  732. }
  733. // GetDataEx 获取指定对手委托
  734. func (r *WrSpecialMatchOrder) GetDataByPage() (interface{}, error, int, int, int) {
  735. sData := make([]WrSpecialMatchOrder, 0)
  736. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  737. total := 0
  738. for i := range sData {
  739. sData[i].calc()
  740. total = sData[i].Total
  741. }
  742. return sData, err, r.Page, r.PageSize, total
  743. }
  744. // WrFactorTypeInfo 仓单要素选择项
  745. type WrFactorTypeInfo struct {
  746. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'" form:"wrfactortypeid"` // 仓单要素ID
  747. DGFACTORYITEMTYPEID int64 `json:"dgfactoryitemtypeid" xorm:"'DGFACTORYITEMTYPEID'"` // 要素选择项ID
  748. ITEMTYPENAME string `json:"itemtypename" xorm:"'ITEMTYPENAME'"` // 要素项名称
  749. DGFACTORYITEMVALUE string `json:"dgfactoryitemvalue" xorm:"'DGFACTORYITEMVALUE'"` // 要素项值
  750. OPTIONCOMPARE string `json:"optioncompare" xorm:"'OPTIONCOMPARE'"` // 选择比较串
  751. WAREHOUSEID int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库id
  752. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  753. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  754. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  755. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  756. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类id
  757. }
  758. func (r *WrFactorTypeInfo) calc() {
  759. }
  760. func (r *WrFactorTypeInfo) buildSql() string {
  761. var sqlId utils.SQLVal = "select t.wrfactortypeid," +
  762. " b.dgfactoryitemtypeid," +
  763. " b.itemtypename," +
  764. " c.dgfactoryitemvalue," +
  765. " t.optioncompare," +
  766. " t.warehouseid," +
  767. " t.wrstandardid," +
  768. " g.deliverygoodsname," +
  769. " g.deliverygoodscode," +
  770. " w.wrstandardcode," +
  771. " w.wrstandardname" +
  772. " from wrfactortype t" +
  773. " inner join wrfactortypeitem a" +
  774. " on t.wrfactortypeid = a.wrfactortypeid" +
  775. " inner join dgfactoryitemtype b" +
  776. " on t.deliverygoodsid = b.deliverygoodsid" +
  777. " and a.dgfactoryitemtypeid = b.dgfactoryitemtypeid" +
  778. " left join dgfactoryitem c" +
  779. " on a.dgfactoryitemid = c.dgfactoryitemid" +
  780. " and b.deliverygoodsid = c.deliverygoodsid" +
  781. " left join deliverygoods g on t.deliverygoodsid=g.deliverygoodsid" +
  782. " left join wrstandard w on t.wrstandardid=w.wrstandardid" +
  783. " where 1 = 1"
  784. sqlId.And("t.wrfactortypeid", r.WRFACTORTYPEID)
  785. return sqlId.String()
  786. }
  787. // GetData 获取仓单要素选择项
  788. func (r *WrFactorTypeInfo) GetData() ([]WrFactorTypeInfo, error) {
  789. sData := make([]WrFactorTypeInfo, 0)
  790. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  791. for i := range sData {
  792. sData[i].calc()
  793. }
  794. return sData, err
  795. }
  796. // WrGoodsPerformanceStep 商品履约步骤
  797. type WrGoodsPerformanceStep struct {
  798. AUTOID int64 `json:"autoid" xorm:"AUTOID" form:"autoid"` // AutoID
  799. TEMPLATEID int64 `json:"templateid" xorm:"TEMPLATEID" form:"templateid"` // 履约计划模板ID
  800. STEPINDEX int32 `json:"stepindex" xorm:"STEPINDEX" form:"stepindex"` // 步骤序号
  801. STEPDAYS int32 `json:"stepdays" xorm:"STEPDAYS" form:"stepdays"` // 距离上一步天数
  802. STEPTYPEID int32 `json:"steptypeid" xorm:"STEPTYPEID" form:"steptypeid"` // 履约步骤类型ID - 1:买方支付 2:卖方收款 3:买方自提 4:卖方发货 5:买方确认货 6:卖方发票 7:买方确认票 8:仓单转移 9:释放卖方冻结 10:货款溢短 11:生成合同[中江] 12:运费 90:确认支付 91. 确认放行 92买方支付(直接扣款) 用于-1模板“
  803. STEPVALUE SFLOAT64 `json:"stepvalue" xorm:"STEPVALUE" form:"stepvalue"` // 步骤值
  804. ISAUTO int32 `json:"isauto" xorm:"ISAUTO" form:"isauto"` // 是否自动 - 0:不自动 1:自动
  805. REMARK string `json:"remark" xorm:"REMARK" form:"remark"` // 备注
  806. STEPTYPENAME string `json:"steptypename" xorm:"'STEPTYPENAME'"` // 步骤名称
  807. STEPINFO string `json:"stepinfo"` // 步骤信息(步骤名称+步骤值)
  808. STEPDAYSINFO string `json:"stepdate"` // 天数信息(T+N)
  809. WRSTANDARDID int64 `json:"-" form:"wrstandardid"` // 商品id
  810. MARKETID int64 `json:"-" form:"marketid"` // 市场id
  811. HASWR int32 `json:"-" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  812. }
  813. func (r *WrGoodsPerformanceStep) calc() {
  814. switch r.STEPTYPEID {
  815. case 1, 2:
  816. r.STEPINFO = fmt.Sprintf("%v% v%%", r.STEPTYPENAME, r.STEPVALUE*100)
  817. default:
  818. if r.STEPVALUE == 0 {
  819. r.STEPINFO = r.STEPTYPENAME
  820. } else {
  821. r.STEPINFO = fmt.Sprintf("%v %v", r.STEPTYPENAME, r.STEPVALUE)
  822. }
  823. }
  824. r.STEPDAYSINFO = fmt.Sprintf("T+%v", r.STEPDAYS)
  825. }
  826. func (r *WrGoodsPerformanceStep) buildSql() string {
  827. var sqlId utils.SQLVal = "with tmp as" +
  828. " (select decode(%v, 1, t.performancetempid, t.performancetempid2) tempid" +
  829. " from marketspotgoodsconfig t" +
  830. " where rownum <= 1 %v)" +
  831. "select t.*, s.steptypename" +
  832. " from PerformanceStepTemplate t" +
  833. " inner join PerformanceStepType s" +
  834. " on t.steptypeid = s.steptypeid" +
  835. " inner join tmp" +
  836. " on t.templateid = tmp.tempid" +
  837. " order by t.stepindex"
  838. var param utils.SQLVal
  839. param.And("t.wrstandardid", r.WRSTANDARDID)
  840. param.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  841. sqlId.FormatParam(r.HASWR, param.String())
  842. return sqlId.String()
  843. }
  844. // GetDataEx 获取商品履约步骤
  845. func (r *WrGoodsPerformanceStep) GetData() ([]WrGoodsPerformanceStep, error) {
  846. sData := make([]WrGoodsPerformanceStep, 0)
  847. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  848. for i := range sData {
  849. sData[i].calc()
  850. sData[i].MARKETID = r.MARKETID
  851. sData[i].WRSTANDARDID = r.WRSTANDARDID
  852. }
  853. return sData, err
  854. }
  855. // WrTypeItem 要素项
  856. type WrTypeItem struct {
  857. NAME string `json:"name"` // 名称
  858. VALUE string `json:"value"` // 值
  859. }
  860. // WrGoodsInfo 仓单商品信息(仓单要素列展开+履约计划步骤)
  861. type WrGoodsInfo struct {
  862. WRFACTORTYPEID int64 `json:"-" form:"wrfactortypeid"` // 仓单要素ID
  863. MARKETID int64 `json:"marketid" form:"marketid"` // 市场id
  864. HASWR int32 `json:"haswr" form:"haswr"` // 0:仓单预售 1:仓单贸易
  865. LstItem []WrTypeItem `json:"lstitem"` // 商品信息项
  866. LstStep []WrGoodsPerformanceStep `json:"lststep"` // 履约规则
  867. }
  868. // GetDataEx 获取仓单商品信息(仓单要素列展开+履约计划步骤)
  869. func (r *WrGoodsInfo) GetDataEx() (interface{}, error) {
  870. sData := make([]WrGoodsInfo, 0)
  871. mWrType := WrFactorTypeInfo{WRFACTORTYPEID: r.WRFACTORTYPEID}
  872. // 获取要素项
  873. if sType, err := mWrType.GetData(); err == nil {
  874. v := WrGoodsInfo{LstItem: make([]WrTypeItem, 0), LstStep: make([]WrGoodsPerformanceStep, 0)}
  875. if len(sType) > 0 {
  876. a := sType[0]
  877. v.LstItem = append(v.LstItem, WrTypeItem{NAME: "品种", VALUE: a.DELIVERYGOODSNAME})
  878. v.LstItem = append(v.LstItem, WrTypeItem{NAME: "品类", VALUE: a.WRSTANDARDNAME})
  879. for _, b := range sType {
  880. v.LstItem = append(v.LstItem, WrTypeItem{NAME: b.ITEMTYPENAME, VALUE: b.DGFACTORYITEMVALUE})
  881. }
  882. // 获取履约规则
  883. mStep := WrGoodsPerformanceStep{MARKETID: r.MARKETID, WRSTANDARDID: a.WRSTANDARDID, HASWR: r.HASWR}
  884. if sStep, err := mStep.GetData(); err == nil && len(sStep) > 0 {
  885. v.LstStep = append(v.LstStep, sStep...)
  886. }
  887. }
  888. v.MARKETID = r.MARKETID
  889. v.HASWR = r.HASWR
  890. v.WRFACTORTYPEID = r.WRFACTORTYPEID
  891. sData = append(sData, v)
  892. }
  893. return sData, nil
  894. }
  895. // WrPerformancePlan 履约信息(履约计划)
  896. type WrPerformancePlan struct {
  897. PERFORMANCEPLANID int64 `json:"performanceplanid" xorm:"PERFORMANCEPLANID" form:"performanceplanid"` // 履约计划ID(130+yyMMddHHmmss+xxxx)
  898. PERFORMANCETYPE int32 `json:"performancetype" xorm:"PERFORMANCETYPE" form:"performancetype"` // 履约类型 - 0:通用 1:交割 2:仓单贸易 3:预售集采 4:竞拍-降价式 (无仓单) 5:挂牌期权 6:竞拍-降价式 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式 10:法币C2C 11:报价系统 12:挂牌系统
  899. RELATEDORDERID string `json:"relatedorderid" xorm:"RELATEDORDERID" form:"relatedorderid"` // 关联单号(履约类型的关联单号)
  900. AMOUNT float64 `json:"amount" xorm:"AMOUNT" form:"amount"` // 履约金额(总金额)
  901. PAYMENTTYPE int32 `json:"paymenttype" xorm:"PAYMENTTYPE" form:"paymenttype"` // 付款方式 - 1:冻结 2:扣款
  902. PERFORMANCESTATUS int32 `json:"performancestatus" xorm:"PERFORMANCESTATUS" form:"performancestatus"` // 履约状态 - 1:初始化 2:正常 3:处理错误 4:违约待处理 5:违约处理中 6:完成 7.违约已完成 8:释放冻结失败 9:超时待处理 10:超时关闭
  903. CURSTEPID int64 `json:"curstepid" xorm:"CURSTEPID" form:"curstepid"` // 当前步骤ID
  904. BUYACCOUNTID int64 `json:"buyaccountid" xorm:"BUYACCOUNTID" form:"buyaccountid"` // 买方账号
  905. WRTRANSFERUSERID int64 `json:"wrtransferuserid" xorm:"WRTRANSFERUSERID" form:"wrtransferuserid"` // 仓单受让用户
  906. BUYPAIDAMOUNT float64 `json:"buypaidamount" xorm:"BUYPAIDAMOUNT" form:"buypaidamount"` // 买方已冻/已扣金额 (已付金额)
  907. SELLACCOUNTID int64 `json:"sellaccountid" xorm:"SELLACCOUNTID" form:"sellaccountid"` // 卖方账号
  908. SELLRECEIVEDAMOUNT float64 `json:"sellreceivedamount" xorm:"SELLRECEIVEDAMOUNT"` // 卖方已收金额
  909. CREATETIME string `json:"createtime" xorm:"CREATETIME" form:"createtime"` // 创建时间(开始时间)
  910. CREATORID int64 `json:"creatorid" xorm:"CREATORID" form:"creatorid"` // 创建人
  911. REMARK string `json:"remark" xorm:"REMARK" form:"remark"` // 备注
  912. BUYERFREEZEAMOUNT float64 `json:"buyerfreezeamount" xorm:"BUYERFREEZEAMOUNT"` // 履约冻结(买履约)
  913. BUYERFREEZEAMOUNTREMAIN float64 `json:"buyerfreezeamountremain" xorm:"BUYERFREEZEAMOUNTREMAIN"` // 履约冻结剩余(买履约)
  914. SELLERFREEZEAMOUNT float64 `json:"sellerfreezeamount" xorm:"SELLERFREEZEAMOUNT"` // 履约冻结(卖履约)
  915. SELLERFREEZEAMOUNTREMAIN float64 `json:"sellerfreezeamountremain" xorm:"SELLERFREEZEAMOUNTREMAIN"` // 履约冻结剩余(卖履约)
  916. OVERSHORTAMOUNT float64 `json:"overshortamount" xorm:"OVERSHORTAMOUNT" form:"overshortamount"` // 溢短金额
  917. HASOVERSHORT int32 `json:"hasovershort" xorm:"HASOVERSHORT" form:"hasovershort"` // 是否确认溢短 - 0:没有 1:买方确认 2:卖方确认
  918. SHIPREMARK string `json:"shipremark" xorm:"SHIPREMARK" form:"shipremark"` // 发货备注[物流单号]
  919. MIDDLEUSERID int64 `json:"middleuserid" xorm:"MIDDLEUSERID" form:"middleuserid"` // 中间商用户ID
  920. MIDDLEACCOUNTID int64 `json:"middleaccountid" xorm:"MIDDLEACCOUNTID" form:"middleaccountid"` // 中间商资金账号ID
  921. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 类型 0-仓单预售 1-仓单贸易
  922. OVERSHORTQTY float64 `json:"overshortqty" xorm:"OVERSHORTQTY" form:"overshortqty"` // 溢短数量
  923. MARKETID int32 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  924. EXPRESSFEECONFIRMED int32 `json:"expressfeeconfirmed" xorm:"EXPRESSFEECONFIRMED"` // 是否确认运费 - 0:无 1:买方确认 2:卖方确认
  925. EXPRESSFEE float64 `json:"expressfee" xorm:"EXPRESSFEE" form:"expressfee"` // 运费
  926. CONTRACTID int64 `json:"contractid" xorm:"CONTRACTID" form:"contractid"` // 合同ID
  927. CURSTEPDEADLINE string `json:"curstepdeadline" xorm:"CURSTEPDEADLINE" form:"curstepdeadline"` // 当前步骤到期时间
  928. QTY float64 `json:"qty" xorm:"QTY" form:"qty"` // 履约数量
  929. Wr2FactorType `xorm:"extends"`
  930. CURSTEPNAME string `json:"curstepname" xorm:"'CURSTEPNAME'"` // 当前步骤名称
  931. BUYUSERNAME string `json:"buyusername" xorm:"'BUYUSERNAME'"` // 买方名字
  932. SELLUSERNAME string `json:"sellusername" xorm:"'SELLUSERNAME'"` // 卖方名字
  933. USERID int64 `json:"userid" form:"userid" binding:"required"` // 用户id
  934. BUYORSELL int32 `json:"buyorsell" form:"buyorsell"` // 买卖方向 0-买 1-卖
  935. }
  936. func (r *WrPerformancePlan) calc() {
  937. }
  938. func (r *WrPerformancePlan) buildSql() string {
  939. var sqlId utils.SQLVal = "with tmp as" +
  940. " (select t.wrfactortypeid," +
  941. " t.wrfactortypename," +
  942. " t.wrstandardid," +
  943. " t.deliverygoodsid," +
  944. " g.deliverygoodscode," +
  945. " g.deliverygoodsname," +
  946. " w.wrstandardcode," +
  947. " w.wrstandardname," +
  948. " h.warehousecode," +
  949. " h.warehousename," +
  950. " e.enumdicname," +
  951. " w.wrstandardname || '-' || t.wrfactortypename as wrtypename" +
  952. " from wrfactortype t" +
  953. " left join deliverygoods g" +
  954. " on t.deliverygoodsid = g.deliverygoodsid" +
  955. " left join wrstandard w" +
  956. " on t.wrstandardid = w.wrstandardid" +
  957. " left join warehouseinfo h" +
  958. " on t.warehouseid = h.autoid" +
  959. " left join enumdicitem e" +
  960. " on w.unitid = e.enumitemname" +
  961. " and e.enumdiccode = 'goodsunit'" +
  962. ")" +
  963. "select to_char(t.PERFORMANCEPLANID) PERFORMANCEPLANID," +
  964. " t.PERFORMANCETYPE," +
  965. " to_char(t.RELATEDORDERID) RELATEDORDERID," +
  966. " t.AMOUNT," +
  967. " t.PAYMENTTYPE," +
  968. " t.PERFORMANCESTATUS," +
  969. " t.CURSTEPID," +
  970. " t.BUYACCOUNTID," +
  971. " t.WRTRANSFERUSERID," +
  972. " t.BUYPAIDAMOUNT," +
  973. " t.SELLACCOUNTID," +
  974. " t.SELLRECEIVEDAMOUNT," +
  975. " t.BUYTODAYAMOUNT," +
  976. " t.SELLTODAYAMOUNT," +
  977. " to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  978. " t.CREATORID," +
  979. " t.REMARK," +
  980. " t.BUYERFREEZEAMOUNT," +
  981. " t.BUYERFREEZEAMOUNTREMAIN," +
  982. " t.SELLERFREEZEAMOUNT," +
  983. " t.SELLERFREEZEAMOUNTREMAIN," +
  984. " t.OVERSHORTAMOUNT," +
  985. " t.HASOVERSHORT," +
  986. " t.SHIPREMARK," +
  987. " t.MIDDLEUSERID," +
  988. " t.MIDDLEACCOUNTID," +
  989. " t.HASWR," +
  990. " t.BUYERINFO," +
  991. " t.SELLERINFO," +
  992. " t.OVERSHORTQTY," +
  993. " t.MARKETID," +
  994. " t.EXPRESSFEECONFIRMED," +
  995. " t.EXPRESSFEE," +
  996. " t.CONTRACTID," +
  997. " to_char(t.CURSTEPDEADLINE, 'yyyy-mm-dd hh24:mi:ss') CURSTEPDEADLINE," +
  998. " t.QTY," +
  999. " u1.accountname buyusername," +
  1000. " u2.accountname sellusername," +
  1001. " s.steptypename CURSTEPNAME," +
  1002. " tmp.*" +
  1003. " from performanceplan t" +
  1004. " left join taaccount a1" +
  1005. " on t.buyaccountid = a1.accountid" +
  1006. " left join useraccount u1" +
  1007. " on a1.userid = u1.userid" +
  1008. " left join taaccount a2" +
  1009. " on t.sellaccountid = a2.accountid" +
  1010. " left join useraccount u2" +
  1011. " on a2.userid = u2.userid" +
  1012. " left join performancesteptype s" +
  1013. " on t.curstepid = s.steptypeid" +
  1014. " left join performanceplanwr p on t.performanceplanid = p.performanceplanid" +
  1015. " left join warehousereciept f on p.wrid= f.wrid" +
  1016. " left join tmp on f.wrfactortypeid=tmp.wrfactortypeid" +
  1017. " where 1 = 1"
  1018. if r.BUYORSELL == 0 {
  1019. sqlId.And("u1.userid", r.USERID)
  1020. } else {
  1021. sqlId.And("u2.userid", r.USERID)
  1022. }
  1023. sqlId.Join(" order by t.CREATETIME desc")
  1024. return sqlId.String()
  1025. }
  1026. // GetDataEx 获取履约信息(履约计划)
  1027. func (r *WrPerformancePlan) GetDataEx() (interface{}, error) {
  1028. sData := make([]WrPerformancePlan, 0)
  1029. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1030. for i := range sData {
  1031. sData[i].calc()
  1032. }
  1033. return sData, err
  1034. }
  1035. // WrHoldLB 仓单持有记录
  1036. type WrHoldLB struct {
  1037. LADINGBILLID int64 `json:"ladingbillid" xorm:"LADINGBILLID" form:"ladingbillid"` // 提单ID(208+Unix秒时间戳(10位)+xxxxxx)
  1038. SUBNUM int32 `json:"subnum" xorm:"SUBNUM" form:"subnum"` // 提单子单号
  1039. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID
  1040. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 品种ID
  1041. QTY float64 `json:"qty" xorm:"QTY" form:"qty"` // 数量
  1042. FREEZERQTY float64 `json:"freezerqty" xorm:"FREEZERQTY" form:"freezerqty"` // 冻结数量
  1043. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 持有人ID
  1044. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid"` // 持有人帐户ID
  1045. CREATETIME string `json:"createtime" xorm:"CREATETIME" form:"createtime"` // 创建时间(过户时间)
  1046. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  1047. WRID int64 `json:"wrid" xorm:"WRID" form:"wrid"` // 仓单变更ID
  1048. PARENTSUBNUM int32 `json:"parentsubnum" xorm:"PARENTSUBNUM" form:"parentsubnum"` // 拆分父子单号
  1049. Wr2FactorType `xorm:"extends"`
  1050. WRHOLDENO string `json:"wrholdeno"` // 仓单编号
  1051. ENABLEQTY float64 `json:"enableqty"` // 可用数量
  1052. }
  1053. func (r *WrHoldLB) calc() {
  1054. r.WRHOLDENO = fmt.Sprintf("%v_%v", r.LADINGBILLID, r.SUBNUM)
  1055. r.ENABLEQTY = r.QTY - r.FREEZERQTY
  1056. }
  1057. func (r *WrHoldLB) buildSql() string {
  1058. var sqlId utils.SQLVal = "with tmp as" +
  1059. " (select t.wrfactortypeid," +
  1060. " t.wrfactortypename," +
  1061. " t.wrstandardid," +
  1062. " t.deliverygoodsid," +
  1063. " g.deliverygoodscode," +
  1064. " g.deliverygoodsname," +
  1065. " w.wrstandardcode," +
  1066. " w.wrstandardname," +
  1067. " h.warehousecode," +
  1068. " h.warehousename," +
  1069. " e.enumdicname," +
  1070. " w.wrstandardname || '-' || t.wrfactortypename as wrtypename" +
  1071. " from wrfactortype t" +
  1072. " left join deliverygoods g" +
  1073. " on t.deliverygoodsid = g.deliverygoodsid" +
  1074. " left join wrstandard w" +
  1075. " on t.wrstandardid = w.wrstandardid" +
  1076. " left join warehouseinfo h" +
  1077. " on t.warehouseid = h.autoid" +
  1078. " left join enumdicitem e" +
  1079. " on w.unitid = e.enumitemname" +
  1080. " and e.enumdiccode = 'goodsunit'" +
  1081. ")" +
  1082. "SELECT t.LADINGBILLID," +
  1083. " t.SUBNUM," +
  1084. " t.WRFACTORTYPEID," +
  1085. " t.DELIVERYGOODSID," +
  1086. " t.QTY," +
  1087. " t.FREEZERQTY," +
  1088. " t.USERID," +
  1089. " t.ACCOUNTID," +
  1090. " to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  1091. " t.TRADEDATE," +
  1092. " t.WRID," +
  1093. " t.PARENTSUBNUM," +
  1094. " tmp.*" +
  1095. " FROM WRHOLDLB t" +
  1096. " LEFT JOIN tmp on t.wrfactortypeid= tmp.wrfactortypeid" +
  1097. " WHERE 1 = 1"
  1098. sqlId.And("t.ACCOUNTID", r.ACCOUNTID)
  1099. return sqlId.String()
  1100. }
  1101. // GetDataEx 获取仓单持有记录
  1102. func (r *WrHoldLB) GetDataEx() (interface{}, error) {
  1103. sData := make([]WrHoldLB, 0)
  1104. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1105. for i := range sData {
  1106. sData[i].calc()
  1107. }
  1108. return sData, err
  1109. }
  1110. // WrFilterItem 筛选框列表项
  1111. type WrFilterItem struct {
  1112. ITEMTYPE int32 `json:"itemtype" xorm:"'ITEMTYPE'"` // 类型 1-品种 2-品类(商品) 3-仓库
  1113. ITEMNAME string `json:"itemname" xorm:"'ITEMNAME'"` // 名称
  1114. ITEMCODE string `json:"itemcode" xorm:"'ITEMCODE'"` // 代码
  1115. ITEMID int64 `json:"itemid" xorm:"'ITEMID'"` // 项id
  1116. IType string `json:"-" form:"itype"` // 类型 逗号隔开, 如 1,2
  1117. }
  1118. func (r *WrFilterItem) calc() {
  1119. }
  1120. func (r *WrFilterItem) buildSql() string {
  1121. if r.IType == "" {
  1122. r.IType = "1, 2, 3"
  1123. }
  1124. r.IType = strings.ReplaceAll(r.IType, " ", "")
  1125. sType := strings.Split(r.IType, ",")
  1126. sqls := make([]string, 0)
  1127. for _, v := range sType {
  1128. switch v {
  1129. case "1":
  1130. sqls = append(sqls, "select 1 itemtype, t.deliverygoodsid itemid, t.deliverygoodscode itemcode, to_char(t.deliverygoodsname) itemname from deliverygoods t")
  1131. case "2":
  1132. sqls = append(sqls, "select 2 itemtype, t.wrstandardid itemid, to_char(t.wrstandardcode) itemcode, to_char(t.wrstandardname) itemname from wrstandard t")
  1133. case "3":
  1134. sqls = append(sqls, "select 3 itemtype, t.autoid itemid, t.warehousecode itemcode, to_char(t.warehousename) itemname from warehouseinfo t")
  1135. default:
  1136. }
  1137. }
  1138. var sqlId string
  1139. for _, v := range sqls {
  1140. if len(sqlId) > 0 {
  1141. sqlId += " union all " + v
  1142. } else {
  1143. sqlId = v
  1144. }
  1145. }
  1146. sqlId += " order by itemtype, itemid"
  1147. return sqlId
  1148. }
  1149. // GetDataEx 获取筛选框列表项
  1150. func (r *WrFilterItem) GetDataEx() (interface{}, error) {
  1151. sData := make([]WrFilterItem, 0)
  1152. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1153. for i := range sData {
  1154. sData[i].calc()
  1155. }
  1156. return sData, err
  1157. }