ermcp3.go 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/4/14 11:11
  4. * @Modify : 2021/4/14 11:11
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/logger"
  11. "mtp2_if/mtpcache"
  12. "mtp2_if/utils"
  13. )
  14. // ErmcpDeliveryGoods 现货品种(交割品种)
  15. type ErmcpDeliveryGoods struct {
  16. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID(SEQ_DELIVERYGOODS)
  17. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  18. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  19. GOODSUNITID int32 `json:"goodsunitid" xorm:"'GOODSUNITID'"` // 现货品种单位ID
  20. DELIVERYGOODSTYPE int32 `json:"deliverygoodstype" xorm:"'DELIVERYGOODSTYPE'"` // 现货品种类型: 1-整装不拆分 2-散装记录明细 3:整装拆分 4:散装不记录明细
  21. STANDARDQTY int32 `json:"standardqty" xorm:"'STANDARDQTY'"` // 标准数量(库位数量) [标准品特有]
  22. STANDARDQTYRANGE int32 `json:"standardqtyrange" xorm:"'STANDARDQTYRANGE'"` // 标准数量偏差范围 [标准品特有]
  23. AUDITFLAG int32 `json:"auditflag" xorm:"'AUDITFLAG'"` // 交割是否需要审核 - 0:不需要 1:需要审核 默认为0
  24. ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  25. AGREEUNIT int32 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位[散货时默认为1, 整装时默认为标准数量]
  26. QTYDECIMALPLACE int32 `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 成交量小数位
  27. CATEGORYID int32 `json:"categoryid" xorm:"'CATEGORYID'"` // 类别ID(SEQ_WRCATEGORY)
  28. DGSTATUS int32 `json:"dgstatus" xorm:"'DGSTATUS'"` // 品种状态 - 作废 - 0:未激活 1:正常
  29. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  30. REMARK string `json:"remark" xorm:"'REMARK'"` // 备注
  31. EnumdicName string `json:"enumdicname"` // 现货品种单位名称
  32. ExcludeCfg int32 `json:"-"` // 排除已配置项 1-排除
  33. }
  34. func (r *ErmcpDeliveryGoods) calc() {
  35. r.EnumdicName = mtpcache.GetEnumDicitemName(r.GOODSUNITID)
  36. }
  37. func (r *ErmcpDeliveryGoods) buildSql() string {
  38. var sqlId utils.SQLVal = "SELECT t.DELIVERYGOODSID," +
  39. " t.DELIVERYGOODSCODE," +
  40. " t.DELIVERYGOODSNAME," +
  41. " t.GOODSUNITID," +
  42. " t.DELIVERYGOODSTYPE," +
  43. " t.STANDARDQTY," +
  44. " t.STANDARDQTYRANGE," +
  45. " t.AUDITFLAG," +
  46. " t.ISVALID," +
  47. " t.ISSPLIT," +
  48. " t.AGREEUNIT," +
  49. " t.QTYDECIMALPLACE," +
  50. " t.CATEGORYID," +
  51. " t.DGSTATUS," +
  52. " t.REMARK," +
  53. " t.AREAUSERID" +
  54. " FROM DELIVERYGOODS t" +
  55. " WHERE 1 = 1"
  56. sqlId.AndEx("t.AREAUSERID", r.AREAUSERID, r.AREAUSERID > 0)
  57. sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  58. if r.ExcludeCfg == 1 {
  59. sqlId.Join(" and t.deliverygoodsid not in(select distinct deliverygoodsid from ermcp_bizgroupspotgoods)")
  60. }
  61. return sqlId.String()
  62. }
  63. // GetDataEx 获取现货商品(交割商品)
  64. func (r *ErmcpDeliveryGoods) GetDataEx() (interface{}, error) {
  65. return r.GetData()
  66. }
  67. // GetData
  68. func (r *ErmcpDeliveryGoods) GetData() ([]ErmcpDeliveryGoods, error) {
  69. sData := make([]ErmcpDeliveryGoods, 0)
  70. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  71. for i := range sData {
  72. sData[i].calc()
  73. }
  74. return sData, err
  75. }
  76. // ErmcpDGFactoryItem 品种选择项定义表
  77. type ErmcpDGFactoryItem struct {
  78. DGFACTORYITEMID int64 `json:"dgfactoryitemid" xorm:"'DGFACTORYITEMID'"` // 选择项ID(SEQ_DGFACTORYITEM)
  79. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
  80. DGFACTORYITEMTYPEID int64 `json:"dgfactoryitemtypeid" xorm:"'DGFACTORYITEMTYPEID'"` // 要素项类型
  81. DGFACTORYITEMVALUE string `json:"dgfactoryitemvalue" xorm:"'DGFACTORYITEMVALUE'"` // 要素项值(类型为仓库时填写仓库名称)
  82. WAREHOUSEID int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库ID(类型为仓库时填写)
  83. ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  84. ORDERINDEX int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 顺序
  85. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 用户id
  86. }
  87. func (r *ErmcpDGFactoryItem) buildSql() string {
  88. var sqlId utils.SQLVal = "SELECT DGFACTORYITEMID," +
  89. " t.DELIVERYGOODSID," +
  90. " to_char(t.DGFACTORYITEMTYPEID) DGFACTORYITEMTYPEID," +
  91. " t.DGFACTORYITEMVALUE," +
  92. " to_char(t.WAREHOUSEID) WAREHOUSEID," +
  93. " t.ISVALID," +
  94. " t.ORDERINDEX," +
  95. " g.areauserid" +
  96. " FROM DGFACTORYITEM t" +
  97. " left join deliverygoods g" +
  98. " on t.deliverygoodsid = g.deliverygoodsid" +
  99. " WHERE t.ISVALID = 1"
  100. sqlId.AndEx("g.areauserid", r.AREAUSERID, r.AREAUSERID > 0)
  101. sqlId.AndEx("t.DGFACTORYITEMID", r.DGFACTORYITEMID, r.DGFACTORYITEMID > 0)
  102. sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  103. sqlId.AndEx("t.DGFACTORYITEMTYPEID", r.DGFACTORYITEMTYPEID, r.DGFACTORYITEMTYPEID > 0)
  104. sqlId.AndEx("t.ORDERINDEX", r.ORDERINDEX, r.ORDERINDEX > 0)
  105. return sqlId.String()
  106. }
  107. // GetDataEx 获取品种选择项定义
  108. func (r *ErmcpDGFactoryItem) GetDataEx() (interface{}, error) {
  109. return r.GetData()
  110. }
  111. // GetData
  112. func (r *ErmcpDGFactoryItem) GetData() (interface{}, error) {
  113. sData := make([]ErmcpDGFactoryItem, 0)
  114. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  115. return sData, err
  116. }
  117. // Ermcp3Brand 品牌(从品种选择项定义表中查)
  118. type Ermcp3Brand struct {
  119. BRANDID int64 `json:"brandid"` // 品牌id
  120. BRANDNAME string `json:"brandname"` // 品牌名称
  121. DELIVERYGOODSID int32 `json:"deliverygoodsid"` // 品种ID
  122. AREAUSERID int64 `json:"areauserid"` // 用户id
  123. }
  124. // GetDataEx
  125. func (r *Ermcp3Brand) GetDataEx() (interface{}, error) {
  126. return r.GetData()
  127. }
  128. // GetData 获取品牌数据
  129. func (r *Ermcp3Brand) GetData() ([]Ermcp3Brand, error) {
  130. m := ErmcpDGFactoryItem{
  131. DELIVERYGOODSID: r.DELIVERYGOODSID,
  132. DGFACTORYITEMTYPEID: 2,
  133. ORDERINDEX: 1,
  134. }
  135. sData := make([]Ermcp3Brand, 0)
  136. if d, err := m.GetDataEx(); err == nil {
  137. if dgLst, ok := d.([]ErmcpDGFactoryItem); ok {
  138. for _, val := range dgLst {
  139. sData = append(sData, Ermcp3Brand{BRANDID: val.DGFACTORYITEMID, AREAUSERID: val.AREAUSERID,
  140. BRANDNAME: val.DGFACTORYITEMVALUE, DELIVERYGOODSID: val.DELIVERYGOODSID})
  141. }
  142. }
  143. }
  144. return sData, nil
  145. }
  146. // ErmcpRelatedGoods 现货品种的关联交易商品
  147. type ErmcpRelatedGoods struct {
  148. GoodsId int `json:"goodsid" xorm:"'GoodsId'"` // 商品id
  149. GoodsCode string `json:"goodscode" xorm:"'GoodsCode'"` // 商品代码
  150. GoodsName string `json:"goodsname" xorm:"'GoodsName'"` // 商品名称
  151. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种ID
  152. AREAUSERID int64 `json:"-"` // 所属机构
  153. }
  154. func (r *ErmcpRelatedGoods) buildSql() string {
  155. var sqlId utils.SQLVal = "select distinct t.deliverygoodsid, g.goodsid, g.goodscode, g.goodsname" +
  156. " from deliverygoods t" +
  157. " inner join ERMS2_WRSConvertDetail w" +
  158. " on t.deliverygoodsid = w.deliverygoodsid" +
  159. " inner join erms_middlegoods m" +
  160. " on w.middlegoodsid = m.middlegoodsid" +
  161. " inner join ERMCP_GGConvertConfig gc" +
  162. " on m.goodsgroupid = gc.destgoodsgroupid" +
  163. " inner join goods g" +
  164. " on gc.srcgoodsgroupid = g.goodsgroupid" +
  165. " where 1 = 1"
  166. sqlId.AndEx("t.AREAUSERID", r.AREAUSERID, r.AREAUSERID > 0)
  167. sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  168. return sqlId.String()
  169. }
  170. // GetDataEx 获取现货关联交易商品
  171. func (r *ErmcpRelatedGoods) GetDataEx() (interface{}, error) {
  172. return r.GetData()
  173. }
  174. // GetData 获取现货关联交易商品
  175. func (r *ErmcpRelatedGoods) GetData() ([]ErmcpRelatedGoods, error) {
  176. sData := make([]ErmcpRelatedGoods, 0)
  177. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  178. return sData, err
  179. }
  180. // ErmcpDeliveryGoodsDetail 现货商品详情
  181. type ErmcpDeliveryGoodsDetail struct {
  182. Data ErmcpDeliveryGoods `json:"data"` // 现货商品基本信息(交割品种)
  183. GmList []Ermcp3Wrstandard `json:"gmlist"` // 品类列表(仓单标准)
  184. GbList []Ermcp3Brand `json:"gblist"` // 品牌列表
  185. }
  186. func (r *ErmcpDeliveryGoodsDetail) addGmList(lst []Ermcp3Wrstandard) {
  187. for i := range lst {
  188. if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID {
  189. r.GmList = append(r.GmList, lst[i])
  190. }
  191. }
  192. }
  193. func (r *ErmcpDeliveryGoodsDetail) addGbList(lst []Ermcp3Brand) {
  194. for i := range lst {
  195. if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID {
  196. r.GbList = append(r.GbList, lst[i])
  197. }
  198. }
  199. }
  200. // GetData
  201. func (r *ErmcpDeliveryGoodsDetail) GetData() ([]ErmcpDeliveryGoodsDetail, error) {
  202. sData := make([]ErmcpDeliveryGoodsDetail, 0)
  203. m := ErmcpDeliveryGoods{AREAUSERID: r.Data.AREAUSERID, DELIVERYGOODSID: r.Data.DELIVERYGOODSID}
  204. data, err := m.GetData()
  205. if err != nil {
  206. return sData, err
  207. }
  208. if data == nil || len(data) == 0 {
  209. return sData, nil
  210. }
  211. // 基本信息
  212. for i := range data {
  213. val := ErmcpDeliveryGoodsDetail{Data: data[i],
  214. GmList: make([]Ermcp3Wrstandard, 0), GbList: make([]Ermcp3Brand, 0),
  215. }
  216. sData = append(sData, val)
  217. }
  218. //品类/品牌/套保信息
  219. gm := Ermcp3Wrstandard{AREAUSERID: int(r.Data.AREAUSERID), DELIVERYGOODSID: r.Data.DELIVERYGOODSID, ISVALID: 1}
  220. gb := Ermcp3Brand{DELIVERYGOODSID: r.Data.DELIVERYGOODSID}
  221. gmLst, _ := gm.GetDataEx()
  222. gbLst, _ := gb.GetData()
  223. for i := range sData {
  224. sData[i].addGmList(gmLst.([]Ermcp3Wrstandard))
  225. sData[i].addGbList(gbLst)
  226. }
  227. return sData, nil
  228. }
  229. // GetDataEx
  230. func (r *ErmcpDeliveryGoodsDetail) GetDataEx() (interface{}, error) {
  231. return r.GetData()
  232. }
  233. // ErmcpDeliveryGoodsDetailEx 现货商品详情(含套保列表)
  234. type ErmcpDeliveryGoodsDetailEx struct {
  235. ErmcpDeliveryGoodsDetail
  236. MgList []Ermcp3MiddleGoodsDetail `json:"mgList"` // 套保列表
  237. }
  238. // GetData 获取现货商品详情(含套保信息列表)
  239. func (r *ErmcpDeliveryGoodsDetailEx) GetDataEx() (interface{}, error) {
  240. sData := make([]ErmcpDeliveryGoodsDetailEx, 0)
  241. mDg := r.ErmcpDeliveryGoodsDetail
  242. // 查现货商品列表
  243. if dgList, err := mDg.GetData(); err == nil {
  244. for i := range dgList {
  245. sData = append(sData, ErmcpDeliveryGoodsDetailEx{ErmcpDeliveryGoodsDetail: dgList[i],
  246. MgList: make([]Ermcp3MiddleGoodsDetail, 0)})
  247. }
  248. }
  249. if len(sData) == 0 {
  250. return sData, nil
  251. }
  252. // 查转换关系
  253. mWc := WRSConverTDetail{}
  254. if wc, err := mWc.GetData(); err == nil {
  255. // 查套保商品列表
  256. mMg := Ermcp3MiddleGoodsDetail{}
  257. mMg.Mg.AREAUSERID = r.Data.AREAUSERID
  258. if mgLst, err := mMg.GetData(); err == nil {
  259. for i := range sData {
  260. sData[i].addMgList(mgLst, wc)
  261. }
  262. }
  263. }
  264. return sData, nil
  265. }
  266. // addMgList 添加关联的套保信息列表
  267. func (r *ErmcpDeliveryGoodsDetailEx) addMgList(lst []Ermcp3MiddleGoodsDetail, wc []WRSConverTDetail) {
  268. for i := range wc {
  269. if r.Data.DELIVERYGOODSID == wc[i].DELIVERYGOODSID {
  270. for k := range lst {
  271. if int64(lst[k].Mg.MIDDLEGOODSID) == wc[i].MIDDLEGOODSID {
  272. r.MgList = append(r.MgList, lst[k])
  273. }
  274. }
  275. }
  276. }
  277. }
  278. // Ermcp3MiddleGoodsDetail 套保品种详情
  279. type Ermcp3MiddleGoodsDetail struct {
  280. Mg ErmcpMiddleGoodsModel `json:"mg"` // 套保商品信息
  281. GPList []Ermcp3GoodsGroupEx `json:"gplist"` // 关联商品组列表
  282. }
  283. // GetData 获取套保品种详情(不含现货列表)
  284. func (r *Ermcp3MiddleGoodsDetail) GetData() ([]Ermcp3MiddleGoodsDetail, error) {
  285. sData := make([]Ermcp3MiddleGoodsDetail, 0)
  286. // 查基本信息
  287. mMg := ErmcpMiddleGoodsModel{AREAUSERID: r.Mg.AREAUSERID, MIDDLEGOODSID: r.Mg.MIDDLEGOODSID, ISVALID: 1}
  288. if mgLst, err := mMg.GetData2(); err == nil {
  289. for i := range mgLst {
  290. sData = append(sData, Ermcp3MiddleGoodsDetail{Mg: mgLst[i], GPList: make([]Ermcp3GoodsGroupEx, 0)})
  291. }
  292. }
  293. if len(sData) == 0 {
  294. return sData, nil
  295. }
  296. mGoods := Ermcp3GoodsEx{AREAUSERID: r.Mg.AREAUSERID}
  297. if gLst, err := mGoods.GetData(); err == nil {
  298. for i := range sData {
  299. sData[i].addGoodsGroup(gLst)
  300. }
  301. for i := range sData {
  302. sData[i].addGoods(gLst)
  303. }
  304. }
  305. return sData, nil
  306. }
  307. func (r *Ermcp3MiddleGoodsDetail) addGoodsGroup(gpLst []Ermcp3GoodsEx) {
  308. for i := range gpLst {
  309. if gpLst[i].MIDDLEGOODSID == r.Mg.MIDDLEGOODSID {
  310. bExist := false
  311. for _, v := range r.GPList {
  312. if v.GOODSGROUPID == gpLst[i].GOODSGROUPID {
  313. bExist = true
  314. break
  315. }
  316. }
  317. if !bExist {
  318. val := Ermcp3GoodsGroupEx{
  319. GOODSGROUPID: gpLst[i].GOODSGROUPID,
  320. MIDDLEGOODSID: gpLst[i].MIDDLEGOODSID,
  321. CONVERTRATIO: gpLst[i].CONVERTRATIO,
  322. EXEXCHANGECODE: gpLst[i].EXEXCHANGECODE,
  323. GOODSGROUPNAME: gpLst[i].GOODSGROUPNAME,
  324. ENUMDICNAME: gpLst[i].ENUMDICNAME,
  325. GList: make([]Ermcp3Goods, 0),
  326. }
  327. r.GPList = append(r.GPList, val)
  328. }
  329. }
  330. }
  331. }
  332. func (r *Ermcp3MiddleGoodsDetail) addGoods(gpLst []Ermcp3GoodsEx) {
  333. for i := range gpLst {
  334. if gpLst[i].MIDDLEGOODSID == r.Mg.MIDDLEGOODSID {
  335. for k := range r.GPList {
  336. if r.GPList[k].GOODSGROUPID == gpLst[i].GOODSGROUPID {
  337. r.GPList[k].GList = append(r.GPList[k].GList, Ermcp3Goods{
  338. GOODSID: gpLst[i].GOODSID,
  339. GOODSNAME: gpLst[i].GOODSNAME,
  340. GOODSCODE: gpLst[i].GOODSCODE,
  341. AGREEUNIT: gpLst[i].AGREEUNIT,
  342. EXEXCHANGECODE: gpLst[i].EXEXCHANGECODE,
  343. ENUMDICNAME: gpLst[i].ENUMDICNAME,
  344. })
  345. }
  346. }
  347. }
  348. }
  349. }
  350. // Ermcp3MiddleGoodsDetailEx 套保品种详情(含现货列表)
  351. type Ermcp3MiddleGoodsDetailEx struct {
  352. Ermcp3MiddleGoodsDetail
  353. DgList []ErmcpDeliveryGoodsDetail `json:"dglist"` // 关联的现货品种列表
  354. }
  355. func (r *Ermcp3MiddleGoodsDetailEx) addDgList(dglst []ErmcpDeliveryGoodsDetail, wc []WRSConverTDetail) {
  356. for i := range wc {
  357. if wc[i].MIDDLEGOODSID == int64(r.Mg.MIDDLEGOODSID) {
  358. for _, detail := range dglst {
  359. if wc[i].DELIVERYGOODSID == detail.Data.DELIVERYGOODSID {
  360. r.DgList = append(r.DgList, detail)
  361. }
  362. }
  363. }
  364. }
  365. }
  366. // GetDataEx
  367. func (r *Ermcp3MiddleGoodsDetailEx) GetDataEx() (interface{}, error) {
  368. sData := make([]Ermcp3MiddleGoodsDetailEx, 0)
  369. // 查套保品种基本信息
  370. m := r.Ermcp3MiddleGoodsDetail
  371. if mgLst, err := m.GetData(); err == nil {
  372. for i := range mgLst {
  373. sData = append(sData, Ermcp3MiddleGoodsDetailEx{Ermcp3MiddleGoodsDetail: mgLst[i],
  374. DgList: make([]ErmcpDeliveryGoodsDetail, 0)})
  375. }
  376. }
  377. // 查转换关系
  378. mWc := WRSConverTDetail{}
  379. if wc, err := mWc.GetData(); err == nil {
  380. // 查现货商品列表
  381. mDg := ErmcpDeliveryGoodsDetail{}
  382. mDg.Data.AREAUSERID = r.Mg.AREAUSERID
  383. if dgLst, err := mDg.GetData(); err == nil {
  384. for i := range sData {
  385. sData[i].addDgList(dgLst, wc)
  386. }
  387. }
  388. }
  389. return sData, nil
  390. }
  391. // Ermcp3GoodsGroupEx 商品组(含商品列表)
  392. type Ermcp3GoodsGroupEx struct {
  393. MIDDLEGOODSID uint32 `json:"middlegoodsid" xorm:"'middlegoodsid'"` // 套保商品id
  394. GOODSGROUPID int32 `json:"goodsgroupid" xorm:"'goodsgroupid'"` // 商品组id
  395. CONVERTRATIO float64 `json:"convertratio" xorm:"'convertratio'"` // 折算系数(品种系数)
  396. EXEXCHANGECODE string `json:"exexchangecode" xorm:"'exexchangecode'"` // 交易所代码
  397. GOODSGROUPNAME string `json:"goodsgroupname" xorm:"'goodsgroupname'"` // 商品组名称
  398. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  399. GList []Ermcp3Goods `json:"glist"` // 合约列表
  400. }
  401. // Ermcp3Goods 商品信息
  402. type Ermcp3Goods struct {
  403. GOODSID int32 `json:"goodsid" xorm:"'goodsid'"` // 期货商品id
  404. GOODSCODE string `json:"goodscode" xorm:"'goodscode'"` // 期货商品代码
  405. GOODSNAME string `json:"goodsname" xorm:"'goodsname'"` // 期货商品名称
  406. AGREEUNIT float32 `json:"agreeunit" xorm:"'agreeunit'"` // 合约单位(合约乘数)
  407. EXEXCHANGECODE string `json:"exexchangecode" xorm:"'exexchangecode'"` // 交易所代码
  408. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  409. }
  410. // Ermcp3GoodsEx 套保品关联的期货商品(少量字段)
  411. type Ermcp3GoodsEx struct {
  412. MIDDLEGOODSID uint32 `json:"middlegoodsid" xorm:"'middlegoodsid'"` // 套保商品id
  413. GOODSID int32 `json:"goodsid" xorm:"'goodsid'"` // 期货商品id
  414. GOODSCODE string `json:"goodscode" xorm:"'goodscode'"` // 期货商品代码
  415. GOODSNAME string `json:"goodsname" xorm:"'goodsname'"` // 期货商品名称
  416. GOODUNITID int32 `json:"goodunitid" xorm:"'goodunitid'"` // 期货商品单位id
  417. CONVERTRATIO float64 `json:"convertratio" xorm:"'convertratio'"` // 折算系数(品种系数)
  418. GOODSGROUPID int32 `json:"goodsgroupid" xorm:"'goodsgroupid'"` // 商品组id
  419. EXEXCHANGECODE string `json:"exexchangecode" xorm:"'exexchangecode'"` // 交易所代码
  420. GOODSGROUPNAME string `json:"goodsgroupname" xorm:"'goodsgroupname'"` // 商品组名称
  421. GPUNITID int32 `json:"gpunitid" xorm:"'gpunitid'"` // 商品组单位id
  422. AGREEUNIT float32 `json:"agreeunit" xorm:"'agreeunit'"` // 合约单位(合约乘数)
  423. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  424. GPENUMDICNAME string `json:"enumdicname"` // 商品组单位名称
  425. AREAUSERID int64 `json:"-"` // 所属机构id
  426. }
  427. func (r *Ermcp3GoodsEx) calc() {
  428. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODUNITID)
  429. r.GPENUMDICNAME = mtpcache.GetEnumDicitemName(r.GPUNITID)
  430. }
  431. func (r *Ermcp3GoodsEx) buildSql() string {
  432. var sqlId utils.SQLVal = "select mg.areauserid," +
  433. " mg.middlegoodsid," +
  434. " g.goodsid," +
  435. " g.goodscode," +
  436. " g.goodsname," +
  437. " g.goodunitid," +
  438. " g.goodsgroupid," +
  439. " g.agreeunit," +
  440. " gc.convertratio," +
  441. " ex.exexchangecode," +
  442. " gp.goodsgroupname," +
  443. " gp.goodunitid gpunitid" +
  444. " from erms_middlegoods mg" +
  445. " inner join ERMCP_GGConvertConfig gc" +
  446. " on mg.goodsgroupid = gc.destgoodsgroupid" +
  447. " inner join goodsgroup gp" +
  448. " on gc.srcgoodsgroupid = gp.goodsgroupid" +
  449. " inner join goods g" +
  450. " on gp.goodsgroupid = g.goodsgroupid" +
  451. " left join externalexchange ex" +
  452. " on gp.exexchangeid = ex.autoid" +
  453. " where 1 = 1"
  454. sqlId.AndEx("mg.areauserid", r.AREAUSERID, r.AREAUSERID > 0)
  455. sqlId.Join(" order by mg.middlegoodsid")
  456. return sqlId.String()
  457. }
  458. // GetData
  459. func (r *Ermcp3GoodsEx) GetData() ([]Ermcp3GoodsEx, error) {
  460. sData := make([]Ermcp3GoodsEx, 0)
  461. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  462. for i := range sData {
  463. sData[i].calc()
  464. }
  465. return sData, err
  466. }
  467. // GetDataEx
  468. func (r *Ermcp3GoodsEx) GetDataEx() (interface{}, error) {
  469. return r.GetData()
  470. }
  471. // Ermcp3Contract 现货合同
  472. type Ermcp3Contract struct {
  473. SPOTCONTRACTID string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'"` // 现货合同ID(602+Unix秒时间戳(10位)+xxxxxx)
  474. CONTRACTNO string `json:"contractno" xorm:"'CONTRACTNO'"` // 现货合同编号
  475. CONTRACTTYPE int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购 -1:销售
  476. USERID int64 `json:"userid" xorm:"'USERID'"` // 所属机构ID
  477. BUYUSERID int64 `json:"buyuserid" xorm:"'BUYUSERID'"` // 采购方ID
  478. BUYUSERName string `json:"buyusername" xorm:"'BUYUSERName'"` // 采购方名称
  479. SELLUSERID int64 `json:"selluserid" xorm:"'SELLUSERID'"` // 销售方ID
  480. SELLUSERNAME string `json:"sellusername" xorm:"'SELLUSERNAME'"` // 销售方名称
  481. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
  482. WRSTANDARDID int32 `json:"wrstandardid" xorm:"'wrstandardid'"` // 品类ID
  483. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  484. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  485. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  486. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  487. PRODUCTTYPE int32 `json:"producttype" xorm:"'PRODUCTTYPE'"` // 产品类型 - 1:标准仓单 2:等标 3:非标
  488. CONVERTFACTOR float64 `json:"convertfactor" xorm:"'CONVERTFACTOR'"` // 标仓系数(品类)
  489. SPOTGOODSDESC string `json:"spotgoodsdesc" xorm:"'SPOTGOODSDESC'"` // 商品型号
  490. PRICETYPE int32 `json:"pricetype" xorm:"'PRICETYPE'"` // 定价类型 - 1:一口价 2:点价 3:暂定价
  491. QTY float64 `json:"qty" xorm:"'QTY'"` // 数量
  492. PRICE float64 `json:"price" xorm:"'PRICE'"` // 价格\暂定价 [1:一口价、3:暂定价]
  493. AMOUNT float64 `json:"amount" xorm:"'AMOUNT'"` // 金额 [1:一口价、3:暂定价]
  494. DELIVERYSTARTDATE string `json:"deliverystartdate" xorm:"'DELIVERYSTARTDATE'"` // 交收期(开始)
  495. DELIVERYENDDATE string `json:"deliveryenddate" xorm:"'DELIVERYENDDATE'"` // 交收期(结束)
  496. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'"` // 点价合约ID - 0:为现货,其它为期货商品合约ID [2:点价 3:暂定价]
  497. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 点价合约代码
  498. GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 点价商品名称
  499. PRICEMOVE float64 `json:"pricemove" xorm:"'PRICEMOVE'"` // 升贴水 [2:点价 3:暂定价]
  500. STARTDATE string `json:"startdate" xorm:"'STARTDATE'"` // 点价开始日期 [2:点价 3:暂定价]
  501. ENDDATE string `json:"enddate" xorm:"'ENDDATE'"` // 点价结束日期 [2:点价 3:暂定价]
  502. MARGIN float64 `json:"margin" xorm:"'MARGIN'"` // 当前保证金
  503. CONTRACTMARGIN float64 `json:"contractmargin" xorm:"'CONTRACTMARGIN'"` // 合同保证金
  504. EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
  505. CONTRACCTSTATUS int32 `json:"contracctstatus" xorm:"'CONTRACTSTATUS'"` // 合同状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
  506. Remark string `json:"remark" xorm:"'Remark'"` // 备注
  507. AUDITREMARK string `json:"auditremark" xorm:"'AUDITREMARK'"` // 审核意见
  508. AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
  509. CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  510. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  511. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID(DGFactoryItem表的ID)
  512. BRANDNAME string `json:"brandname" xorm:"'brandname'"` // 品牌名称
  513. ATTACHMENT string `json:"attachment" xorm:"'ATTACHMENT'"` // 附件
  514. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位id(取品类上的单位id)
  515. TRADEUSERID int64 `json:"tradeuserid" xorm:"'TRADEUSERID'"` // 交易员id
  516. SALEUSERID int64 `json:"saleuserid" xorm:"'SALEUSERID'"` // 业务员id
  517. MERUSERID int64 `json:"meruserid" xorm:"'MERUSERID'"` // 跟单员id
  518. ACCOUNTID string `json:"accountid" xorm:"'ACCOUNTID'"` // 期货账户id
  519. BIZTYPE int32 `json:"biztype" xorm:"'BIZTYPE'"` // 业务类型 1-套保 2-套利
  520. SELLNICKNAME string `json:"sellnickname"` // 采购方昵称
  521. BUYNICKNAME string `json:"buynickname"` // 销售方昵称
  522. TRADEUSERLOGINCODE string `json:"tradeuserlogincode"` // 交易员登录代码
  523. SALEUSERLOGINCODE string `json:"saleuserlogincode"` // 业务员登录代码
  524. MERUSERLOGINCODE string `json:"meruserlogincode"` // 跟单员登录代码
  525. // 筛选条件
  526. QryType int32 `json:"-"` // 查询类型 1-未提交 2-待审核 3-履约中 4-已完成
  527. UserType int32 `json:"-"` // 用户类型 2-管理员 7-企业成员
  528. OwnUserId int64 `json:"-"` // 登录用户id
  529. }
  530. func (r *Ermcp3Contract) getQryTypeStatus() string {
  531. var status string
  532. switch r.QryType {
  533. case 1: // 未提交
  534. status = "0,4,6"
  535. case 2: // 待审核
  536. status = "1"
  537. case 3: // 履约中
  538. status = "2"
  539. case 4: // 已完成
  540. status = "3,5"
  541. }
  542. return status
  543. }
  544. func (r *Ermcp3Contract) calc() {
  545. r.BUYUSERName, r.BUYNICKNAME = mtpcache.GetUserNameAndNickName(r.BUYUSERID)
  546. r.SELLUSERNAME, r.SELLNICKNAME = mtpcache.GetUserNameAndNickName(r.SELLUSERID)
  547. r.EnumdicName = mtpcache.GetEnumDicitemName(r.UNITID)
  548. r.TRADEUSERLOGINCODE = mtpcache.GetLoginCodeByUserId(r.TRADEUSERID)
  549. r.SALEUSERLOGINCODE = mtpcache.GetLoginCodeByUserId(r.SALEUSERID)
  550. r.MERUSERLOGINCODE = mtpcache.GetLoginCodeByUserId(r.MERUSERID)
  551. }
  552. func (r *Ermcp3Contract) buildSql() string {
  553. var sqlId utils.SQLVal = "SELECT to_char(t.SPOTCONTRACTID) SPOTCONTRACTID," +
  554. " t.CONTRACTNO," +
  555. " t.CONTRACTTYPE," +
  556. " t.USERID," +
  557. " t.BUYUSERID," +
  558. " t.SELLUSERID," +
  559. " t.DELIVERYGOODSID," +
  560. " t.wrstandardid," +
  561. " t.PRODUCTTYPE," +
  562. " w.CONVERTFACTOR," +
  563. " t.SPOTGOODSDESC," +
  564. " t.PRICETYPE," +
  565. " t.QTY," +
  566. " t.PRICE," +
  567. " t.AMOUNT," +
  568. " to_char(t.DELIVERYSTARTDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYSTARTDATE," +
  569. " to_char(t.DELIVERYENDDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYENDDATE," +
  570. " t.GOODSID," +
  571. " t.PRICEMOVE," +
  572. " to_char(t.STARTDATE, 'yyyy-mm-dd hh24:mi:ss') STARTDATE," +
  573. " to_char(t.ENDDATE, 'yyyy-mm-dd hh24:mi:ss') ENDDATE," +
  574. " t.MARGIN," +
  575. " t.contractmargin," +
  576. " t.remark," +
  577. " t.auditremark," +
  578. " to_char(t.contractattachment) attachment," +
  579. " t.contractstatus," +
  580. " t.SPOTGOODSBRANDID," +
  581. " to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
  582. " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
  583. " to_char(t.updatetime, 'yyyy-mm-dd hh24:mi:ss') updatetime," +
  584. " g.deliverygoodscode," +
  585. " g.deliverygoodsname," +
  586. " g2.goodscode," +
  587. " g2.goodsname," +
  588. " gb.dgfactoryitemvalue brandname," +
  589. " w.wrstandardname," +
  590. " w.wrstandardcode," +
  591. " w.unitid," +
  592. " t.tradeuserid," +
  593. " t.saleuserid," +
  594. " t.meruserid," +
  595. " to_char(t.accountid) accountid," +
  596. " t.biztype" +
  597. " FROM ERMCP_SPOTCONTRACT t" +
  598. " left join deliverygoods g" +
  599. " on t.deliverygoodsid = g.deliverygoodsid" +
  600. " left join goods g2" +
  601. " on t.goodsid = g2.goodsid" +
  602. " left join DGFACTORYITEM gb" +
  603. " on t.spotgoodsbrandid = gb.dgfactoryitemid" +
  604. " left join wrstandard w" +
  605. " on t.wrstandardid = w.wrstandardid" +
  606. " where 1 = 1"
  607. sqlId.AndEx("t.userid", r.USERID, r.USERID > 0)
  608. sqlId.AndEx("t.SPOTCONTRACTID", r.SPOTCONTRACTID, len(r.SPOTCONTRACTID) > 0)
  609. if r.UserType == 7 {
  610. // 企业成员
  611. sqlId.Join(fmt.Sprintf(" and %v in(t.saleuserid, t.tradeuserid, t.meruserid)", r.OwnUserId))
  612. }
  613. status := r.getQryTypeStatus()
  614. if len(status) > 0 {
  615. sqlId.Join(fmt.Sprintf(" and t.contractstatus in (%v)", status))
  616. }
  617. return sqlId.String()
  618. }
  619. // GetDataEx
  620. func (r *Ermcp3Contract) GetDataEx() (interface{}, error) {
  621. sData := make([]Ermcp3Contract, 0)
  622. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  623. for i := range sData {
  624. sData[i].calc()
  625. }
  626. return sData, err
  627. }
  628. // Ermcp3SellBuyContract 采购/销售合同
  629. type Ermcp3SellBuyContract struct {
  630. UserID int64 `json:"userid" xorm:"'UserID'"` // 机构ID
  631. SpotContractId string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'"` // 合同ID
  632. AccountName string `json:"accountname" xorm:"'ACCOUNTNAME'"` // 账户名称
  633. DeliveryGoodsId int `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货商品ID
  634. DeliveryGoodsCode string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  635. DeliveryGoodsName string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  636. SpotGoodsdesc string `json:"spotgoodsdesc" xorm:"'SPOTGOODSDESC'"` // 商品型号(商品规格)
  637. GoodsId int `json:"goodsid" xorm:"'GOODSID'"` // 点价商品ID
  638. GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 点价商品名称
  639. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 点价商品代码
  640. Pricemove float64 `json:"pricemove" xorm:"'PRICEMOVE'"` // 升贴水
  641. Qty float64 `json:"qty" xorm:"'QTY'"` // 合同量
  642. UnpricedQty float64 `json:"unpricedqty" xorm:"'UNPRICEDQTY'"` // 未定价量
  643. PricedQty float64 `json:"pricedqty" xorm:"'PRICEDQTY'"` // 已定价量
  644. UnsureQty float64 `json:"unsureqty" xorm:"'UNSUREQTY'"` // 未确定量
  645. PayAmount float64 `json:"payamount" xorm:"'PAYAMOUNT'"` // 已收付额(收款或付款)
  646. UnpayAmount float64 `json:"unpayamount"` // 应收付款额(应支付或应收款)
  647. PrePayAmount float64 `json:"prepayamount"` // 预收付额
  648. InvoiceAmount float64 `json:"invoiceamount" xorm:"'INVOICEAMOUNT'"` // 已开票额
  649. DaikaiAmount float64 `json:"daikaiamount" xorm:"'DAIKAIAMOUNT'"` // 应收(开)票额
  650. PreInvoiceAmount float64 `json:"preinvoiceamount"` // 预收(开)票额
  651. StartDate string `json:"startdate" xorm:"'STARTDATE'"` // 点价开始日
  652. EndDate string `json:"enddate" xorm:"'ENDDATE'"` // 点价结束日
  653. DeliveryStartDate string `json:"deliverystartdate" xorm:"'DELIVERYSTARTDATE'"` // 交割开始日
  654. DeliveryendDate string `json:"deliveryenddate" xorm:"'DELIVERYENDDATE'"` // 交割结束日
  655. Convertfactor float64 `json:"convertfactor" xorm:"'CONVERTFACTOR'"` // 标仓系数(品类)
  656. EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
  657. Contracctstatus uint `json:"contracctstatus" xorm:"'CONTRACTSTATUS'"` // 合同状态- 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
  658. PriceType int `json:"pricetype" xorm:"'PRICETYPE'"` // 定价类型 - 1:一口价 2:点价 3:暂定价
  659. ProductType int `json:"producttype" xorm:"'PRODUCTTYPE'"` // 产品类型 - 1:标准仓单 2:等标 3:非标
  660. Contracttype int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 合同类型 1-采购, -1-销售
  661. Pricedamount float64 `json:"pricedamount" xorm:"'PRICEDAMOUNT'"` // 已定价额
  662. PricedAvg float64 `json:"pricedavg" xorm:"'PRICEDAVG'"` // 已点均价
  663. Margin float64 `json:"margin" xorm:"'MARGIN'"` // 保证金
  664. CONTRACTMARGIN float64 `json:"contractmargin" xorm:"'CONTRACTMARGIN'"` // 合同保证金
  665. Remark string `json:"remark" xorm:"'Remark'"` // 备注
  666. ATTACHMENT string `json:"attachment" xorm:"'ATTACHMENT'"` // 附件
  667. ReckonRealQty float64 `json:"reckonrealqty" xorm:"'ReckonRealQty'"` // 已确定量
  668. ReckonOtherAmount float64 `json:"reckonotheramount" xorm:"'ReckonOtherAmount'"` // 其它费用
  669. ReckonAdjustAmount float64 `json:"reckonadjustamount" xorm:"'ReckonAdjustAmount'"` // 调整金额
  670. Price float64 `json:"price" xorm:"'Price'"` // 价格
  671. LoanAmount float64 `json:"loanamount" xorm:"'LoanAmount'"` // 贷款总额=已定价额+调整金额
  672. Contractno string `json:"contractno" xorm:"'Contractno'"` // 合同编号
  673. TotalAmount float64 `json:"totalamount" xorm:"'-'"` // 合计总额
  674. ReckonedAmount float64 `json:"reckonedamount" xorm:"'ReckonedAmount'"` // 实际已收付额(已确定额,已收付总额-已退款总额)
  675. BUYUSERID int64 `json:"-" xorm:"'BUYUSERID'"` // 采购方ID
  676. SELLUSERID int64 `json:"-" xorm:"'SELLUSERID'"` // 销售方ID
  677. AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
  678. CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  679. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID(DGFactoryItem表的ID)
  680. BRANDNAME string `json:"brandname" xorm:"'brandname'"` // 品牌名称
  681. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类ID
  682. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  683. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  684. NICKNAME string `json:"nickname"` // 账户昵称
  685. // 筛选条件
  686. QryType int32 `json:"-"` // 查询类型 1-未提交 2-待审核 3-履约中 4-已完成
  687. UserType int32 `json:"-"` // 用户类型 2-管理员 7-企业成员
  688. OwnUserId int64 `json:"-"` // 登录用户id
  689. }
  690. func (r *Ermcp3SellBuyContract) calc() {
  691. r.TotalAmount = r.LoanAmount + r.ReckonOtherAmount
  692. r.UnpayAmount = r.TotalAmount - r.ReckonedAmount
  693. r.PrePayAmount = r.ReckonedAmount - r.TotalAmount
  694. r.PreInvoiceAmount = r.InvoiceAmount - r.TotalAmount
  695. if r.Contracttype == 1 {
  696. //采购合同, 取销售方名称
  697. r.AccountName, r.NICKNAME = mtpcache.GetUserNameAndNickName(r.SELLUSERID)
  698. } else {
  699. //销售合同, 取采购方名称
  700. r.AccountName, r.NICKNAME = mtpcache.GetUserNameAndNickName(r.BUYUSERID)
  701. }
  702. }
  703. func (r *Ermcp3SellBuyContract) buildSql() string {
  704. var sqlId utils.SQLVal = "select t.contractno," +
  705. " to_char(t.SpotContractId) SpotContractId," +
  706. " t.deliverygoodsid," +
  707. " t.spotgoodsdesc," +
  708. " t.goodsid," +
  709. " t.pricemove," +
  710. " t.userid," +
  711. " t.BUYUSERID," +
  712. " t.SELLUSERID," +
  713. " t.qty," +
  714. " t.qty - t.pricedqty unpricedqty," +
  715. " t.pricedqty," +
  716. " (case" +
  717. " when t.pricetype = 3 then" +
  718. " t.qty - t.RECKONREALQTY" +
  719. " else" +
  720. " t.pricedqty - t.ReckonRealQty" +
  721. " end) unsureqty," +
  722. " t.reckonedamount PayAmount," +
  723. " t.invoiceamount," +
  724. " (t.pricedamount + t.RECKONADJUSTAMOUNT + t.RECKONOTHERAMOUNT -" +
  725. " t.invoiceamount) as daikaiAmount," +
  726. " to_char(t.startdate, 'yyyy-mm-dd hh24:mi:ss') startdate," +
  727. " to_char(t.enddate, 'yyyy-mm-dd hh24:mi:ss') enddate," +
  728. " to_char(t.deliverystartdate, 'yyyy-mm-dd hh24:mi:ss') deliverystartdate," +
  729. " to_char(t.deliveryenddate, 'yyyy-mm-dd hh24:mi:ss') deliveryenddate," +
  730. " wr.convertfactor," +
  731. " t.contractstatus," +
  732. " t.pricetype," +
  733. " t.producttype," +
  734. " t.contracttype," +
  735. " t.remark," +
  736. " to_char(t.contractattachment) attachment," +
  737. " t.margin," +
  738. " t.contractmargin," +
  739. " t.SPOTGOODSBRANDID," +
  740. " g.deliverygoodscode," +
  741. " g.deliverygoodsname," +
  742. " wr.wrstandardid," +
  743. " wr.wrstandardname," +
  744. " wr.wrstandardcode," +
  745. " g2.goodscode," +
  746. " g2.goodsname," +
  747. " e.enumdicname," +
  748. " t.contracttype," +
  749. " t.pricedamount," +
  750. " case" +
  751. " when t.pricedqty > 0 then" +
  752. " (t.pricedamount) / t.pricedqty" +
  753. " else" +
  754. " 0" +
  755. " end pricedAvg," +
  756. " t.ReckonRealQty," +
  757. " t.ReckonOtherAmount," +
  758. " t.ReckonAdjustAmount," +
  759. " t.Price," +
  760. " t.ReckonedAmount," +
  761. " to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
  762. " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
  763. " t.pricedamount + t.ReckonAdjustAmount as LoanAmount," +
  764. " gb.dgfactoryitemvalue BRANDNAME" +
  765. " from ermcp_spotcontract t" +
  766. " left join deliverygoods g" +
  767. " on t.deliverygoodsid = g.deliverygoodsid" +
  768. " left join goods g2" +
  769. " on t.goodsid = g2.goodsid" +
  770. " left join wrstandard wr" +
  771. " on t.wrstandardid = wr.wrstandardid" +
  772. " left join DGFactoryItem gb" +
  773. " on t.spotgoodsbrandid = gb.dgfactoryitemid" +
  774. " left join enumdicitem e" +
  775. " on wr.unitid = e.enumitemname" +
  776. " and e.enumdiccode = 'goodsunit'" +
  777. " where 1 = 1"
  778. sqlId.AndEx("t.userid", r.UserID, r.UserID > 0)
  779. sqlId.AndEx("t.contracttype", r.Contracttype, r.Contracttype != 0)
  780. sqlId.AndEx("t.SpotContractId", r.SpotContractId, len(r.SpotContractId) > 0)
  781. if r.UserType == 7 {
  782. // 企业成员
  783. sqlId.Join(fmt.Sprintf(" and %v in(t.saleuserid, t.tradeuserid, t.meruserid)", r.OwnUserId))
  784. }
  785. var status string
  786. nQueryType := r.QryType
  787. if 1 == nQueryType {
  788. // 全部
  789. status = "2,3"
  790. } else if 2 == nQueryType {
  791. // 待点价
  792. status = "2"
  793. } else {
  794. // 履约
  795. status = "2"
  796. }
  797. if len(status) > 0 {
  798. sqlId.Join(fmt.Sprintf(" and t.contractstatus in (%v)", status))
  799. }
  800. sqlId.JoinEx(r.QryType == 2, " and t.qty - t.pricedqty > 0 and t.pricetype !=1")
  801. return sqlId.String()
  802. }
  803. // GetDataEx
  804. func (r *Ermcp3SellBuyContract) GetDataEx() (interface{}, error) {
  805. sData := make([]Ermcp3SellBuyContract, 0)
  806. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  807. for i := range sData {
  808. sData[i].calc()
  809. }
  810. return sData, err
  811. }
  812. // Ermcp3ExposureDetail 敞口现货明细
  813. type Ermcp3ExposureDetail struct {
  814. Createtime string `json:"createtime" xorm:"'createtime'"` // 时间
  815. Areauserid int64 `json:"areauserid" xorm:"'areauserid'"` // 机构ID
  816. Logtype int32 `json:"logtype" xorm:"'logtype'"` // 类型 - 1:套保计划 2:现货合同
  817. Contracttype int32 `json:"contracttype" xorm:"'contracttype'"` // 现货合同类型 - 1:采购 -1:销售
  818. Qty float64 `json:"qty" xorm:"'qty'"` // 数量
  819. RelateNo string `json:"relateNo" xorm:"'relateNo'"` // 现货合同/套保计划编号
  820. Middlegoodsname string `json:"middlegoodsname" xorm:"'middlegoodsname'"` // 套保商品名称
  821. Middlegoodscode string `json:"middlegoodscode" xorm:"'middlegoodscode'"` // 套保商品代码
  822. MiddlegoodsId int32 `json:"middlegoodsId" xorm:"'middlegoodsId'"` // 套保商品id
  823. Unitid int32 `json:"-" xorm:"'unitid'"` // 现货商品单位ID
  824. Enumdicname string `json:"enumdicname" xorm:"'enumdicname'"` // 现货商品单位名称
  825. ChangeQty float64 `json:"changeQty" xorm:"'changeQty'"` // 套保变动量
  826. Convertfactor float64 `json:"convertfactor" xorm:"'convertfactor'"` // 标仓系数
  827. Convertratio float64 `json:"convertratio" xorm:"'convertratio'"` // 套保系数
  828. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  829. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  830. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  831. }
  832. func (r *Ermcp3ExposureDetail) calc() {
  833. // 销售合同转换为负数
  834. if r.Logtype == 2 && r.Contracttype == -1 {
  835. r.ChangeQty *= -1
  836. r.Qty *= -1
  837. }
  838. // 采购计划 转换为负数
  839. if r.Logtype == 1 && r.Contracttype == 1 {
  840. r.ChangeQty *= -1
  841. r.Qty *= -1
  842. }
  843. }
  844. func (r *Ermcp3ExposureDetail) buildSql() string {
  845. var sqlId utils.SQLVal = "with tmp as" +
  846. " (select 2 as LogType," +
  847. " s.spotcontractid as relatedid," +
  848. " s.contractno as relateNo," +
  849. " s.qty" +
  850. " from ermcp_spotcontract s" +
  851. " union all" +
  852. " select 1," +
  853. " t.hedgeplanid as relateid," +
  854. " t.hedgeplanno as relateNo," +
  855. " t.planqty as qty" +
  856. " from ermcp_hedgeplan t)" +
  857. "select to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
  858. " t.middlegoodsid," +
  859. " t.areauserid," +
  860. " t.logtype," +
  861. " t.contracttype," +
  862. " t.qty / t.convertfactor / t.convertratio as qty," +
  863. " t.convertfactor," +
  864. " t.convertratio," +
  865. " t.qty changeQty," +
  866. " tmp.relateNo," +
  867. " m.middlegoodsname," +
  868. " m.middlegoodscode," +
  869. " g.deliverygoodsid," +
  870. " g.deliverygoodscode," +
  871. " g.deliverygoodsname," +
  872. " g.goodsunitid unitid," +
  873. " e.enumdicname" +
  874. " from ermcp_spotexposurelog t" +
  875. " left join erms_middlegoods m" +
  876. " on t.middlegoodsid = m.middlegoodsid" +
  877. " left join deliverygoods g" +
  878. " on t.deliverygoodsid = g.deliverygoodsid" +
  879. " left join enumdicitem e" +
  880. " on g.goodsunitid = e.enumitemname" +
  881. " and e.enumdiccode = 'goodsunit'" +
  882. " left join tmp" +
  883. " on t.logtype = tmp.LogType" +
  884. " and t.relatedid = tmp.relatedid" +
  885. " where 1=1 and t.tradedate=to_char(sysdate, 'yyyymmdd')"
  886. sqlId.And("t.areauserid", r.Areauserid)
  887. sqlId.And("t.middlegoodsid", r.MiddlegoodsId)
  888. return sqlId.String()
  889. }
  890. // GetDataEx
  891. func (r *Ermcp3ExposureDetail) GetDataEx() (interface{}, error) {
  892. e := db.GetEngine()
  893. s := e.SQL(r.buildSql())
  894. sData := make([]Ermcp3ExposureDetail, 0)
  895. if err := s.Find(&sData); err != nil {
  896. return nil, err
  897. }
  898. for i := range sData {
  899. sData[i].calc()
  900. }
  901. return sData, nil
  902. }
  903. // Ermcp3AreaSpot 敞口现货头寸
  904. type Ermcp3AreaSpot struct {
  905. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  906. ORIBUYPLANQTY float64 `json:"-" xorm:"'ORIBUYPLANQTY'"` // 期初采购计划数量
  907. ORIBUYPRICEDQTY float64 `json:"-" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购合同已定价数量
  908. ORISELLPLANQTY float64 `json:"-" xorm:"'ORISELLPLANQTY'"` // 期初销售计划数量
  909. ORISELLPRICEDQTY float64 `json:"-" xorm:"'ORISELLPRICEDQTY'"` // 期初销售合同已定价数量
  910. BUYPLANQTY float64 `json:"-" xorm:"'BUYPLANQTY'"` // 采购计划数量
  911. BUYPRICEDQTY float64 `json:"-" xorm:"'BUYPRICEDQTY'"` // 采购合同已定价数量
  912. SELLPLANQTY float64 `json:"-" xorm:"'SELLPLANQTY'"` // 销售计划数量
  913. SELLPRICEDQTY float64 `json:"-" xorm:"'SELLPRICEDQTY'"` // 销售合同已定价数量
  914. TOTALSPOTQTY float64 `json:"totalspotqty" xorm:"'TOTALSPOTQTY'"` // 当前数量(现货头寸总量) = (销售计划数量 - 销售已定价数量) - (采购计划数量 - 采购已定价数量)
  915. OriToalSpotQty float64 `json:"oritoalspotqty" xorm:"'OriToalSpotQty'"` // 昨日数量
  916. IncreaseQty float64 `json:"increaseqty" xorm:"'IncreaseQty'"` // 增加数量=销售计划数量+采购已定价数量
  917. DecreaseQty float64 `json:"decreaseqty" xorm:"'DecreaseQty'"` // 减少数量=-(销售已定价数量+采购计划数量)
  918. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  919. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  920. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  921. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  922. }
  923. func (r *Ermcp3AreaSpot) calc() {
  924. /*
  925. 增加数量=今日销售计划数量+今日采购已定价数量
  926. 减少数量=-(今日销售已定价数量+今日采购计划数量)
  927. 其中,
  928. 今日销售计划数量=期末销售计划数量-期初销售计划数量
  929. 今日采购已定价数量=期末采购已定价数量-期初采购已定价数量
  930. 今日销售已定价数量=期末销售已定价数量-期初销售已定价数量
  931. 今日采购计划数量=期末采购计划数量-期初采购计划数量
  932. */
  933. r.IncreaseQty = r.SELLPLANQTY - r.ORISELLPLANQTY + r.BUYPRICEDQTY - r.ORIBUYPRICEDQTY
  934. r.DecreaseQty = (r.SELLPRICEDQTY - r.ORISELLPRICEDQTY + r.BUYPLANQTY - r.ORIBUYPLANQTY) * -1
  935. r.OriToalSpotQty = (r.ORISELLPLANQTY - r.ORISELLPRICEDQTY) - (r.ORIBUYPLANQTY - r.ORIBUYPRICEDQTY)
  936. }
  937. func (r *Ermcp3AreaSpot) buildSql() string {
  938. var sqlId utils.SQLVal = "select t.AREAUSERID," +
  939. " t.ORIBUYPLANQTY," +
  940. " t.ORIBUYPRICEDQTY," +
  941. " t.ORISELLPLANQTY," +
  942. " t.ORISELLPRICEDQTY," +
  943. " t.BUYPLANQTY," +
  944. " t.BUYPRICEDQTY," +
  945. " t.SELLPLANQTY," +
  946. " t.SELLPRICEDQTY," +
  947. " t.TOTALSPOTQTY," +
  948. " g.deliverygoodsid," +
  949. " g.deliverygoodscode," +
  950. " g.deliverygoodsname," +
  951. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME" +
  952. " from ermcp_areaspot t" +
  953. " left join deliverygoods g" +
  954. " on t.deliverygoodsid = g.deliverygoodsid" +
  955. " where 1 = 1"
  956. sqlId.And("t.areauserid", r.AREAUSERID)
  957. return sqlId.String()
  958. }
  959. // GetDataEx
  960. func (r *Ermcp3AreaSpot) GetDataEx() (interface{}, error) {
  961. e := db.GetEngine()
  962. s := e.SQL(r.buildSql())
  963. sData := make([]Ermcp3AreaSpot, 0)
  964. if err := s.Find(&sData); err != nil {
  965. return nil, err
  966. }
  967. for i := range sData {
  968. sData[i].calc()
  969. }
  970. return sData, nil
  971. }
  972. // Ermcp3AreaSpotDetail 敞口现货头寸明细
  973. type Ermcp3AreaSpotDetail struct {
  974. Relatedid string `json:"relatedid" xorm:"'relatedid'"` // 套保计划ID/现货合同ID
  975. Relatedno string `json:"relatedno" xorm:"'relatedno'"` // 编号
  976. LogType int32 `json:"logtype" xorm:"'logType'"` // 记录类型 1-套保 2-现货合同
  977. Contracttype int32 `json:"contracttype" xorm:"'contracttype'"` // 合同类型 1-采购 -1-销售
  978. Qty float64 `json:"qty" xorm:"'qty'"` // 数量
  979. Strtime string `json:"strtime" xorm:"'strtime'"` // 时间
  980. Enumdicname string `json:"enumdicname"` // 现货商品单位名称
  981. Recordname string `json:"recordname"` // 类型名称
  982. CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  983. Unitid int32 `json:"-" xorm:"'UNITID'"` // 单位ID
  984. UserId int `json:"-"` // 所属用户ID
  985. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  986. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  987. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  988. }
  989. func (r *Ermcp3AreaSpotDetail) calc() {
  990. var logTypeName, contractTypeName string
  991. if r.LogType == 1 {
  992. logTypeName = "计划"
  993. } else {
  994. logTypeName = "合同"
  995. }
  996. if r.Contracttype == 1 {
  997. contractTypeName = "采购"
  998. } else {
  999. contractTypeName = "销售"
  1000. }
  1001. // 销售合同 数量转为负数
  1002. if r.LogType == 2 && r.Contracttype == -1 {
  1003. if r.Qty > 0 {
  1004. r.Qty = r.Qty * -1
  1005. }
  1006. }
  1007. // 采购计划 数量转为负数
  1008. if r.LogType == 1 && r.Contracttype == 1 {
  1009. if r.Qty > 0 {
  1010. r.Qty = r.Qty * -1
  1011. }
  1012. }
  1013. r.Recordname = contractTypeName + logTypeName
  1014. r.Enumdicname = mtpcache.GetEnumDicitemName(r.Unitid)
  1015. }
  1016. func (r *Ermcp3AreaSpotDetail) buildSql() string {
  1017. var sqlId utils.SQLVal = "with tmp as" +
  1018. " (select to_char(t.hedgeplanid) relatedid," +
  1019. " t.hedgeplanno relatedno," +
  1020. " 1 as logType," +
  1021. " t.contracttype" +
  1022. " from ermcp_hedgeplan t" +
  1023. " where t.areauserid = %v" +
  1024. " and t.deliverygoodsid = %v" +
  1025. " union all" +
  1026. " select to_char(t.spotcontractid)," +
  1027. " t.contractno," +
  1028. " 2 as logType," +
  1029. " t.contracttype" +
  1030. " from ermcp_spotcontract t" +
  1031. " where t.userid = %v" +
  1032. " and t.deliverygoodsid = %v)" +
  1033. "select t.relatedid," +
  1034. " tmp.relatedno," +
  1035. " t.LogType," +
  1036. " tmp.contracttype," +
  1037. " t.RealQty qty," +
  1038. " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
  1039. " g.deliverygoodsid," +
  1040. " g.deliverygoodsname," +
  1041. " g.deliverygoodscode," +
  1042. " g.goodsunitid unitid" +
  1043. " from ermcp_spotlog t" +
  1044. " inner join tmp" +
  1045. " on t.LogType = tmp.logType" +
  1046. " and t.relatedid = tmp.relatedid" +
  1047. " and t.areauserid = %v" +
  1048. " and t.deliverygoodsid = %v" +
  1049. " left join deliverygoods g" +
  1050. " on t.deliverygoodsid = g.deliverygoodsid" +
  1051. " where t.tradedate = to_char(sysdate, 'yyyymmdd')"
  1052. sqlId.FormatParam(r.UserId, r.DELIVERYGOODSID, r.UserId, r.DELIVERYGOODSID, r.UserId, r.DELIVERYGOODSID)
  1053. return sqlId.String()
  1054. }
  1055. // GetDataEx
  1056. func (r *Ermcp3AreaSpotDetail) GetDataEx() (interface{}, error) {
  1057. e := db.GetEngine()
  1058. s := e.SQL(r.buildSql())
  1059. sData := make([]Ermcp3AreaSpotDetail, 0)
  1060. if err := s.Find(&sData); err != nil {
  1061. return nil, err
  1062. }
  1063. for i := range sData {
  1064. sData[i].calc()
  1065. }
  1066. return sData, nil
  1067. }
  1068. // Ermcp3Wrstandard 现货品类
  1069. type Ermcp3Wrstandard struct {
  1070. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类ID(SEQ_WRSTANDARD)
  1071. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  1072. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
  1073. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 品类单位ID
  1074. MINIVALUE int32 `json:"minivalue" xorm:"'MINIVALUE'"` // 最小变动值
  1075. MINIVALUEDP int32 `json:"minivaluedp" xorm:"'MINIVALUEDP'"` // 最小变动值小数位
  1076. REALMINIVALUE int32 `json:"realminivalue" xorm:"'REALMINIVALUE'"` // 实际最小变动值
  1077. REALMINIVALUEDP int32 `json:"realminivaluedp" xorm:"'REALMINIVALUEDP'"` // 实际最小变动值小数位
  1078. CREATORID int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  1079. CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  1080. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  1081. AREAUSERID int `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  1082. EnumdicName string `json:"enumdicname"` // 品类单位名称
  1083. ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 0-无效(停用) 1-有效(正常)
  1084. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  1085. REMARK string `json:"remark" xorm:"'REMARK'"` // 备注
  1086. CONVERTFACTOR float64 `json:"convertfactor" xorm:"'CONVERTFACTOR'"` // 标仓系数
  1087. }
  1088. func (r *Ermcp3Wrstandard) calc() {
  1089. r.EnumdicName = mtpcache.GetEnumDicitemName(r.UNITID)
  1090. }
  1091. func (r *Ermcp3Wrstandard) buildSql() string {
  1092. str := "select WRSTANDARDID," +
  1093. " WRSTANDARDCODE," +
  1094. " DELIVERYGOODSID," +
  1095. " UNITID," +
  1096. " MINIVALUE," +
  1097. " MINIVALUEDP," +
  1098. " REALMINIVALUE," +
  1099. " REALMINIVALUEDP," +
  1100. " CREATORID," +
  1101. " to_char(CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  1102. " WRSTANDARDNAME," +
  1103. " ISVALID," +
  1104. " to_char(UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
  1105. " REMARK," +
  1106. " CONVERTFACTOR," +
  1107. " AREAUSERID" +
  1108. " from wrstandard t" +
  1109. " where t.AREAUSERID=%v"
  1110. sqlId := fmt.Sprintf(str, r.AREAUSERID)
  1111. if r.DELIVERYGOODSID > 0 {
  1112. sqlId = sqlId + fmt.Sprintf(" and DELIVERYGOODSID=%v", r.DELIVERYGOODSID)
  1113. }
  1114. sqlId += " order by createtime desc"
  1115. return sqlId
  1116. }
  1117. // GetDataEx
  1118. func (r *Ermcp3Wrstandard) GetDataEx() (interface{}, error) {
  1119. e := db.GetEngine()
  1120. s := e.SQL(r.buildSql())
  1121. sData := make([]Ermcp3Wrstandard, 0)
  1122. if err := s.Find(&sData); err != nil {
  1123. return nil, err
  1124. }
  1125. for i := range sData {
  1126. sData[i].calc()
  1127. }
  1128. return sData, nil
  1129. }
  1130. // Ermcp3AreaStockApply 出入库申请
  1131. type Ermcp3AreaStockApply struct {
  1132. INOUTAPPLYID string `json:"inoutapplyid" xorm:"'INOUTAPPLYID'"` // 申请ID(607+Unix秒时间戳(10位)+xxxxxx)
  1133. USERID int64 `json:"userid" xorm:"'USERID'"` // 机构ID
  1134. INOUTTYPE int32 `json:"inouttype" xorm:"'INOUTTYPE'"` // 出入库类型 - 1:采购入库 2:销售出库 3:生产入库 4:生产出库
  1135. WRSTANDARDID int32 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类ID
  1136. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID
  1137. SPOTCONTRACTID string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'"` // 关联现货合同ID
  1138. WAREHOUSEINFOID string `json:"warehouseinfoid" xorm:"'WAREHOUSEINFOID'"` // 现货仓库ID
  1139. QTY float64 `json:"qty" xorm:"'QTY'"` // 数量
  1140. APPLYSTATUS int32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回
  1141. APPLYSRC int32 `json:"applysrc" xorm:"'APPLYSRC'"` // 申请来源 - 1:管理端 2:终端
  1142. APPLYID int64 `json:"applyid" xorm:"'APPLYID'"` // 申请人
  1143. APPLYREMARK string `json:"applyremark" xorm:"'APPLYREMARK'"` // 申请备注
  1144. APPLYTIME string `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间
  1145. AUDITSRC int32 `json:"auditsrc" xorm:"'AUDITSRC'"` // 审核来源 - 1:管理端 2:终端
  1146. AUDITID int64 `json:"auditid" xorm:"'AUDITID'"` // 审核人
  1147. AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
  1148. AUDITREMARK string `json:"auditremark" xorm:"'AUDITREMARK'"` // 审核备注
  1149. AUDITTRADEDATE string `json:"audittradedate" xorm:"'AUDITTRADEDATE'"` // 审核交易日(yyyyMMdd)
  1150. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  1151. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  1152. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位id
  1153. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  1154. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  1155. WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码
  1156. WAREHOUSETYPE int32 `json:"warehousetype" xorm:"'WAREHOUSETYPE'"` // 仓库类型 - 1 厂库 2 自有库 3 合作库
  1157. CONTRACTNO string `json:"contractno" xorm:"'CONTRACTNO'"` // 合同编号
  1158. CONTRACTTYPE int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购 -1:销售
  1159. BUYUSERID int64 `json:"buyuserid" xorm:"'BUYUSERID'"` // 采购方userid
  1160. SELLUSERID int64 `json:"selluserid" xorm:"'SELLUSERID'"` // 销售方userid
  1161. PRICETYPE int32 `json:"pricetype" xorm:"'PRICETYPE'"` // 定价类型 - 1:一口价 2:点价 3:暂定价
  1162. CONTRACTQTY float64 `json:"contractqty" xorm:"'CONTRACTQTY'"` // 合同量
  1163. BUYUSERNAME string `json:"buyusername"` // 采购方名称
  1164. SELLUSERNAME string `json:"sellusername"` // 销售方名称
  1165. APPLYNAME string `json:"applyname"` // 申请人名称
  1166. AUDITNAME string `json:"auditname"` // 审核人名称
  1167. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  1168. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  1169. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  1170. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  1171. BUYNICKNAME string `json:"buynickname"` // 采购方昵称
  1172. SELLNICKNAME string `json:"sellnickname"` // 销售方昵称
  1173. FilterStatus string `json:"-"` // 查询条件, 申请状态, 逗号隔开
  1174. FilterType string `json:"-"` // 查询条件, 出入库类型, 逗号隔开
  1175. BeginDate string `json:"-"` // 开始日期
  1176. EndDate string `json:"-"` // 结束日期
  1177. }
  1178. func (r *Ermcp3AreaStockApply) calc() {
  1179. // 采购方名称
  1180. r.BUYUSERNAME, r.BUYNICKNAME = mtpcache.GetUserNameAndNickName(r.BUYUSERID)
  1181. // 销售方名称
  1182. r.SELLUSERNAME, r.SELLNICKNAME = mtpcache.GetUserNameAndNickName(r.SELLUSERID)
  1183. // 申请人名称
  1184. if r.APPLYSRC == 1 {
  1185. r.APPLYNAME = mtpcache.GetSystemmangerLoginCode(r.APPLYID)
  1186. } else {
  1187. r.APPLYNAME = mtpcache.GetLoginCodeByLoginId(r.APPLYID)
  1188. }
  1189. // 审核人名称
  1190. if r.AUDITSRC == 1 {
  1191. r.AUDITNAME = mtpcache.GetSystemmangerLoginCode(r.AUDITID)
  1192. } else {
  1193. r.AUDITNAME = mtpcache.GetLoginCodeByLoginId(r.AUDITID)
  1194. }
  1195. // 单位名称
  1196. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  1197. }
  1198. func (r *Ermcp3AreaStockApply) buildSql() string {
  1199. var sqlId utils.SQLVal = "SELECT to_char(t.INOUTAPPLYID) INOUTAPPLYID," +
  1200. " t.USERID," +
  1201. " t.INOUTTYPE," +
  1202. " t.WRSTANDARDID," +
  1203. " t.SPOTGOODSBRANDID," +
  1204. " t.DELIVERYGOODSID," +
  1205. " to_char(t.SPOTCONTRACTID) SPOTCONTRACTID," +
  1206. " to_char(t.WAREHOUSEINFOID) WAREHOUSEINFOID," +
  1207. " t.QTY," +
  1208. " t.APPLYSTATUS," +
  1209. " t.APPLYSRC," +
  1210. " t.APPLYID," +
  1211. " t.APPLYREMARK," +
  1212. " to_char(t.APPLYTIME, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME," +
  1213. " t.AUDITSRC," +
  1214. " t.AUDITID," +
  1215. " to_char(t.AUDITTIME, 'yyyy-mm-dd hh24:mi:ss') AUDITTIME," +
  1216. " t.AUDITREMARK," +
  1217. " t.AUDITTRADEDATE," +
  1218. " w.wrstandardname," +
  1219. " w.wrstandardcode," +
  1220. " g.goodsunitid unitid," +
  1221. " gb.dgfactoryitemvalue brandname," +
  1222. " h.warehousename," +
  1223. " h.warehousecode," +
  1224. " h.warehousetype," +
  1225. " s.contractno," +
  1226. " s.contracttype," +
  1227. " s.buyuserid," +
  1228. " s.selluserid," +
  1229. " s.pricetype," +
  1230. " s.qty CONTRACTQTY," +
  1231. " g.deliverygoodscode," +
  1232. " g.deliverygoodsname" +
  1233. " FROM ERMCP_AREAINOUTSTOCKAPPLY t" +
  1234. " left join wrstandard w" +
  1235. " on t.wrstandardid = w.wrstandardid" +
  1236. " left join dgfactoryitem gb" +
  1237. " on t.spotgoodsbrandid = gb.dgfactoryitemid" +
  1238. " left join deliverygoods g" +
  1239. " on t.deliverygoodsid = g.deliverygoodsid" +
  1240. " left join warehouseinfo h" +
  1241. " on t.warehouseinfoid = h.autoid" +
  1242. " left join ermcp_spotcontract s" +
  1243. " on t.spotcontractid = s.spotcontractid" +
  1244. " WHERE 1 = 1"
  1245. // 用户id(必要条件)
  1246. sqlId.And("t.USERID", r.USERID)
  1247. // 合同id
  1248. if len(r.SPOTCONTRACTID) > 0 {
  1249. sqlId.And("t.SPOTCONTRACTID", r.SPOTCONTRACTID)
  1250. }
  1251. // 现货品种id
  1252. if r.DELIVERYGOODSID > 0 {
  1253. sqlId.And("t.DELIVERYGOODSID", r.DELIVERYGOODSID)
  1254. }
  1255. // 品类id
  1256. if r.WRSTANDARDID > 0 {
  1257. sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
  1258. }
  1259. // 品牌id
  1260. if r.SPOTGOODSBRANDID > 0 {
  1261. sqlId.And("t.SPOTGOODSBRANDID", r.SPOTGOODSBRANDID)
  1262. }
  1263. // 仓库id
  1264. if len(r.WAREHOUSEINFOID) > 0 {
  1265. sqlId.And("t.WAREHOUSEINFOID", r.WAREHOUSEINFOID)
  1266. }
  1267. // 日期范围
  1268. if len(r.BeginDate) > 0 {
  1269. if r.BeginDate == r.EndDate {
  1270. sqlId.And("t.audittradedate", r.BeginDate)
  1271. } else if r.EndDate > r.BeginDate {
  1272. sqlId.BiggerOrEq("t.audittradedate", r.BeginDate)
  1273. sqlId.LessOrEq("t.audittradedate", r.EndDate)
  1274. }
  1275. }
  1276. // 出入库类型
  1277. if len(r.FilterType) > 0 {
  1278. if len(r.FilterType) == 1 {
  1279. sqlId.And("t.INOUTTYPE", r.FilterType)
  1280. } else {
  1281. sqlId.Join(fmt.Sprintf(" and t.INOUTTYPE in(%v)", r.FilterType))
  1282. }
  1283. }
  1284. // 出入库状态
  1285. if len(r.FilterStatus) > 0 {
  1286. sqlId.Join(fmt.Sprintf(" and t.APPLYSTATUS in(%v)", r.FilterStatus))
  1287. }
  1288. // 排序
  1289. sqlId.Join(" order by t.APPLYTIME desc")
  1290. return sqlId.String()
  1291. }
  1292. // GetDataEx 查询库存申请(记录)
  1293. func (r *Ermcp3AreaStockApply) GetDataEx() (interface{}, error) {
  1294. sData := make([]Ermcp3AreaStockApply, 0)
  1295. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1296. if err == nil {
  1297. for i := range sData {
  1298. sData[i].calc()
  1299. }
  1300. }
  1301. return sData, err
  1302. }
  1303. // Ermcp3AreaStockApplySum 合同出入库数量汇总
  1304. type Ermcp3AreaStockApplySum struct {
  1305. INOUTTYPE int32 `json:"inouttype" xorm:"'INOUTTYPE'"` // 出入库类型 - 1:采购入库 2:销售出库 3:生产入库 4:生产出库
  1306. WRSTANDARDID int32 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类id
  1307. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 品牌id
  1308. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  1309. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  1310. TOTALQTY float64 `json:"totalqty" xorm:"'TOTALQTY'"` // 总数量
  1311. SPOTCONTRACTID string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'"` // 关联现货合同ID
  1312. }
  1313. func (r *Ermcp3AreaStockApplySum) buildSql() string {
  1314. sqlId := "select a.*, gb.dgfactoryitemvalue brandname, w.wrstandardname" +
  1315. " from (SELECT t.INOUTTYPE," +
  1316. " t.wrstandardid," +
  1317. " t.SPOTGOODSBRANDID," +
  1318. " t.SPOTCONTRACTID," +
  1319. " sum(t.QTY) TOTALQTY" +
  1320. " FROM ERMCP_AREAINOUTSTOCKAPPLY t" +
  1321. " WHERE t.applystatus = 2" +
  1322. " and t.spotcontractid = %v" +
  1323. " group by t.inouttype," +
  1324. " t.spotgoodsbrandid," +
  1325. " t.wrstandardid," +
  1326. " t.spotcontractid) a" +
  1327. " left join dgfactoryitem gb" +
  1328. " on a.spotgoodsbrandid = gb.dgfactoryitemid" +
  1329. " left join wrstandard w" +
  1330. " on a.wrstandardid = w.wrstandardid"
  1331. sqlId = fmt.Sprintf(sqlId, r.SPOTCONTRACTID)
  1332. // 不关联合同id
  1333. sqlId2 := "select a.*, gb.dgfactoryitemvalue brandname, w.wrstandardname" +
  1334. " from (SELECT t.INOUTTYPE," +
  1335. " t.wrstandardid," +
  1336. " t.SPOTGOODSBRANDID," +
  1337. " t.SPOTCONTRACTID," +
  1338. " sum(t.QTY) TOTALQTY" +
  1339. " FROM ERMCP_AREAINOUTSTOCKAPPLY t" +
  1340. " WHERE t.applystatus = 2" +
  1341. " group by t.inouttype," +
  1342. " t.spotgoodsbrandid," +
  1343. " t.wrstandardid," +
  1344. " t.spotcontractid) a" +
  1345. " left join dgfactoryitem gb" +
  1346. " on a.spotgoodsbrandid = gb.dgfactoryitemid" +
  1347. " left join wrstandard w" +
  1348. " on a.wrstandardid = w.wrstandardid"
  1349. if len(r.SPOTCONTRACTID) == 0 {
  1350. return sqlId2
  1351. }
  1352. return sqlId
  1353. }
  1354. // GetDataEx 获取合同出入库汇总信息
  1355. func (r *Ermcp3AreaStockApplySum) GetDataEx() (interface{}, error) {
  1356. sData := make([]Ermcp3AreaStockApplySum, 0)
  1357. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1358. return sData, err
  1359. }
  1360. // Ermcp3AreaStock 机构库存表
  1361. type Ermcp3AreaStock struct {
  1362. TODAYBUYINQTY float64 `json:"todaybuyinqty" xorm:"'TODAYBUYINQTY'"` // 今日采购入库量
  1363. TODAYPRODUCEINQTY float64 `json:"todayproduceinqty" xorm:"'TODAYPRODUCEINQTY'"` // 今日生产入库量
  1364. TODAYSELLOUTQTY float64 `json:"todayselloutqty" xorm:"'TODAYSELLOUTQTY'"` // 今日销售出库量
  1365. TODAYPRODUCEOUTQTY float64 `json:"todayproduceoutqty" xorm:"'TODAYPRODUCEOUTQTY'"` // 今日生产出库量
  1366. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  1367. USERID int64 `json:"userid" xorm:"'USERID'" form:"userid" binding:"required"` // 机构ID
  1368. WRSTANDARDID string `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类ID
  1369. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID
  1370. WAREHOUSEINFOID string `json:"warehouseinfoid" xorm:"'WAREHOUSEINFOID'"` // 仓库ID
  1371. ORISTOCK float64 `json:"oristock" xorm:"'ORISTOCK'"` // 期初库存量(昨日量)
  1372. CURSTOCK float64 `json:"curstock" xorm:"'CURSTOCK'"` // 期末库存量(今日量)
  1373. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  1374. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  1375. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位id
  1376. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  1377. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  1378. WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码
  1379. WAREHOUSETYPE int32 `json:"warehousetype" xorm:"'WAREHOUSETYPE'"` // 仓库类型 - 1 厂库 2 自有库 3 合作库
  1380. USERNAME string `json:"username"` // 机构名称
  1381. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  1382. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  1383. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  1384. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  1385. GOODSUNITID int32 `json:"goodsunitid" xorm:"'GOODSUNITID'"` // 现货商品单位id
  1386. }
  1387. func (r *Ermcp3AreaStock) calc() {
  1388. r.USERNAME = mtpcache.GetUserNameByUserId(r.USERID)
  1389. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  1390. }
  1391. func (r *Ermcp3AreaStock) buildSql() string {
  1392. var sqlId utils.SQLVal = "SELECT t.TODAYBUYINQTY," +
  1393. " t.TODAYPRODUCEINQTY," +
  1394. " t.TODAYSELLOUTQTY," +
  1395. " t.TODAYPRODUCEOUTQTY," +
  1396. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
  1397. " t.USERID," +
  1398. " t.WRSTANDARDID," +
  1399. " t.SPOTGOODSBRANDID," +
  1400. " t.WAREHOUSEINFOID," +
  1401. " t.DELIVERYGOODSID," +
  1402. " t.ORISTOCK," +
  1403. " t.CURSTOCK," +
  1404. " w.wrstandardname," +
  1405. " w.wrstandardcode," +
  1406. " w.unitid," +
  1407. " gb.dgfactoryitemvalue brandname," +
  1408. " h.warehousename," +
  1409. " h.warehousecode," +
  1410. " h.warehousetype," +
  1411. " g.deliverygoodsid," +
  1412. " g.deliverygoodscode," +
  1413. " g.deliverygoodsname," +
  1414. " g.goodsunitid" +
  1415. " FROM ERMCP_AREASTOCK t" +
  1416. " LEFT JOIN WRSTANDARD w" +
  1417. " on t.wrstandardid = w.wrstandardid" +
  1418. " LEFT JOIN dgfactoryitem gb" +
  1419. " on t.spotgoodsbrandid = gb.dgfactoryitemvalue" +
  1420. " LEFT JOIN deliverygoods g" +
  1421. " on t.deliverygoodsid = g.deliverygoodsid" +
  1422. " LEFT JOIN WAREHOUSEINFO h" +
  1423. " on t.warehouseinfoid = h.autoid" +
  1424. " WHERE 1 = 1"
  1425. sqlId.And("t.USERID", r.USERID)
  1426. sqlId.Join(" order by t.WRSTANDARDID, t.UPDATETIME desc")
  1427. return sqlId.String()
  1428. }
  1429. // GetDataEx 获取机构库存信息
  1430. func (r *Ermcp3AreaStock) GetDataEx() (interface{}, error) {
  1431. sData := make([]Ermcp3AreaStock, 0)
  1432. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1433. if err == nil {
  1434. for i := range sData {
  1435. sData[i].calc()
  1436. }
  1437. }
  1438. return sData, err
  1439. }
  1440. // Ermcp3AreaStockReport 库存报表
  1441. type Ermcp3AreaStockReport struct {
  1442. USERID int64 `json:"userid" xorm:"'USERID'"` // 机构ID
  1443. WRSTANDARDID int32 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类ID
  1444. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID
  1445. WAREHOUSEINFOID string `json:"warehouseinfoid" xorm:"'WAREHOUSEINFOID'"` // 仓库ID
  1446. ORISTOCK float64 `json:"oristock" xorm:"'ORISTOCK'"` // 期初库存量
  1447. CURSTOCK float64 `json:"curstock" xorm:"'CURSTOCK'"` // 期末库存量
  1448. TODAYBUYINQTY float64 `json:"todaybuyinqty" xorm:"'TODAYBUYINQTY'"` // 今日采购入库量
  1449. TODAYPRODUCEINQTY float64 `json:"todayproduceinqty" xorm:"'TODAYPRODUCEINQTY'"` // 今日生产入库量
  1450. TODAYSELLOUTQTY float64 `json:"todayselloutqty" xorm:"'TODAYSELLOUTQTY'"` // 今日销售出库量
  1451. TODAYPRODUCEOUTQTY float64 `json:"todayproduceoutqty" xorm:"'TODAYPRODUCEOUTQTY'"` // 今日生产出库量
  1452. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  1453. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  1454. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  1455. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 品类单位id
  1456. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  1457. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  1458. WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码
  1459. WAREHOUSETYPE int32 `json:"warehousetype" xorm:"'WAREHOUSETYPE'"` // 仓库类型 - 1 厂库 2 自有库 3 合作库
  1460. USERNAME string `json:"username"` // 机构名称
  1461. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  1462. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  1463. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  1464. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  1465. GOODSUNITID int32 `json:"goodsunitid" xorm:"'GOODSUNITID'"` // 现货单位id
  1466. ReportType int32 `json:"-"` // 报表类型 1-日报表 2-月报表
  1467. ReportDate string `json:"-"` // 格式 日报表(YYYYMMDD) 月报表(YYYYMM)
  1468. }
  1469. func (r *Ermcp3AreaStockReport) calc() {
  1470. r.USERNAME = mtpcache.GetUserNameByUserId(r.USERID)
  1471. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  1472. }
  1473. func (r *Ermcp3AreaStockReport) buildSql() string {
  1474. var sqlId utils.SQLVal = "SELECT t.TODAYBUYINQTY," +
  1475. " t.TODAYPRODUCEINQTY," +
  1476. " t.TODAYSELLOUTQTY," +
  1477. " t.TODAYPRODUCEOUTQTY," +
  1478. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
  1479. " t.USERID," +
  1480. " t.WRSTANDARDID," +
  1481. " t.SPOTGOODSBRANDID," +
  1482. " t.WAREHOUSEINFOID," +
  1483. " t.ORISTOCK," +
  1484. " t.CURSTOCK," +
  1485. " w.wrstandardname," +
  1486. " w.wrstandardcode," +
  1487. " w.unitid," +
  1488. " gb.dgfactoryitemvalue brandname," +
  1489. " h.warehousename," +
  1490. " h.warehousecode," +
  1491. " h.warehousetype," +
  1492. " g.deliverygoodsid," +
  1493. " g.deliverygoodscode," +
  1494. " g.deliverygoodsname," +
  1495. " g.goodsunitid" +
  1496. " FROM %v t" +
  1497. " LEFT JOIN WRSTANDARD w" +
  1498. " on t.wrstandardid = w.wrstandardid" +
  1499. " LEFT JOIN dgfactoryitem gb" +
  1500. " on t.spotgoodsbrandid = gb.dgfactoryitemid" +
  1501. " LEFT JOIN deliverygoods g" +
  1502. " on t.deliverygoodsid = g.deliverygoodsid" +
  1503. " LEFT JOIN WAREHOUSEINFO h" +
  1504. " on t.warehouseinfoid = h.autoid" +
  1505. " WHERE 1 = 1"
  1506. sqlId.And("t.USERID", r.USERID)
  1507. if r.ReportType == 1 {
  1508. // 日报表
  1509. sqlId.FormatParam("RECKON_ERMCP_AREASTOCK")
  1510. sqlId.And("t.reckondate", r.ReportDate)
  1511. } else {
  1512. // 月报表
  1513. sqlId.FormatParam("REPORT_ERMCP_AREASTOCK")
  1514. sqlId.And("t.cycletype", 1)
  1515. sqlId.And("t.cycletime", r.ReportDate)
  1516. }
  1517. // 现货商品id
  1518. sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  1519. // 品类id
  1520. sqlId.AndEx("t.WRSTANDARDID", r.WRSTANDARDID, r.WRSTANDARDID > 0)
  1521. // 品牌id
  1522. if r.SPOTGOODSBRANDID > 0 {
  1523. sqlId.And("t.SPOTGOODSBRANDID", r.SPOTGOODSBRANDID)
  1524. }
  1525. // 仓库id
  1526. if len(r.WAREHOUSEINFOID) > 0 {
  1527. sqlId.And("t.WAREHOUSEINFOID", r.WAREHOUSEINFOID)
  1528. }
  1529. return sqlId.String()
  1530. }
  1531. // GetDataEx 查询库存报表
  1532. func (r *Ermcp3AreaStockReport) GetDataEx() (interface{}, error) {
  1533. sData := make([]ErmcpAreaStockReport, 0)
  1534. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1535. if err == nil {
  1536. for i := range sData {
  1537. sData[i].calc()
  1538. }
  1539. }
  1540. return sData, err
  1541. }
  1542. // Ermcp3SpotGoodsPrice 现货市价
  1543. type Ermcp3SpotGoodsPrice struct {
  1544. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货品类ID(通用则为0)
  1545. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID(通用则为0, 不为0则须先有品类ID)
  1546. CURRENCYID int64 `json:"currencyid" xorm:"'CURRENCYID'"` // 报价货币ID
  1547. SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"'SPOTGOODSPRICE'"` // 现货价格
  1548. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  1549. OPERATESRC int32 `json:"operatesrc" xorm:"'OPERATESRC'"` // 最后操作来源 - 1:管理端 2:终端
  1550. OPERATEID int64 `json:"operateid" xorm:"'OPERATEID'"` // 最后操作人
  1551. OPERATETIME string `json:"operatetime" xorm:"'OPERATETIME'"` // 最后操作时间
  1552. ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  1553. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构id
  1554. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  1555. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  1556. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 现货商品单位id
  1557. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  1558. GMUNITID int32 `json:"gmunitid" xorm:"'GMUNITID'"` // 品类单位id
  1559. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货商品id
  1560. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货商品代码
  1561. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货商品名称
  1562. OPERATORNAME string `json:"operatorname"` // 操作人名称
  1563. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  1564. GBENUMDICNAME string `json:"gbenumdicname"` // 品类单位名称
  1565. }
  1566. func (r *Ermcp3SpotGoodsPrice) calc() {
  1567. if r.OPERATESRC == 1 {
  1568. r.OPERATORNAME = mtpcache.GetSystemmangerLoginCode(r.OPERATEID)
  1569. } else {
  1570. r.OPERATORNAME = mtpcache.GetLoginCodeByLoginId(r.OPERATEID)
  1571. }
  1572. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  1573. r.GBENUMDICNAME = mtpcache.GetEnumDicitemName(r.GMUNITID)
  1574. }
  1575. func (r *Ermcp3SpotGoodsPrice) buildSql() string {
  1576. var sqlId utils.SQLVal = "SELECT t.WRSTANDARDID," +
  1577. " t.SPOTGOODSBRANDID," +
  1578. " t.CURRENCYID," +
  1579. " t.SPOTGOODSPRICE," +
  1580. " t.TRADEDATE," +
  1581. " t.OPERATESRC," +
  1582. " t.OPERATEID," +
  1583. " to_char(t.OPERATETIME, 'yyyy-mm-dd hh24:mi:ss') OPERATETIME," +
  1584. " t.ISVALID," +
  1585. " w.areauserid," +
  1586. " w.wrstandardcode," +
  1587. " w.wrstandardname," +
  1588. " w.unitid gmunitid," +
  1589. " gb.dgfactoryitemvalue brandname," +
  1590. " g.deliverygoodsid," +
  1591. " g.deliverygoodscode," +
  1592. " g.deliverygoodsname," +
  1593. " g.goodsunitid unitid" +
  1594. " FROM ERMCP_SPOTGOODSPRICE t" +
  1595. " left join wrstandard w" +
  1596. " on t.wrstandardid = w.wrstandardid" +
  1597. " left join dgfactoryitem gb" +
  1598. " on t.spotgoodsbrandid = gb.dgfactoryitemid" +
  1599. " left join deliverygoods g" +
  1600. " on t.deliverygoodsid = g.deliverygoodsid" +
  1601. " WHERE 1 = 1"
  1602. sqlId.And("w.areauserid", r.AREAUSERID)
  1603. return sqlId.String()
  1604. }
  1605. // GetDataEx 获取现货市价
  1606. func (r *Ermcp3SpotGoodsPrice) GetDataEx() (interface{}, error) {
  1607. sData := make([]Ermcp3SpotGoodsPrice, 0)
  1608. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1609. if err == nil {
  1610. for i := range sData {
  1611. sData[i].calc()
  1612. }
  1613. }
  1614. return sData, err
  1615. }
  1616. // Ermcp3SpotGoodsPriceLog 现货市价操作日志
  1617. type Ermcp3SpotGoodsPriceLog struct {
  1618. LOGID int64 `json:"logid" xorm:"'LOGID'"` // 日志id
  1619. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货品类ID(通用则为0)
  1620. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID(通用则为0, 不为0则须先有品类ID)
  1621. CURRENCYID int64 `json:"currencyid" xorm:"'CURRENCYID'"` // 报价货币ID
  1622. SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"'SPOTGOODSPRICE'"` // 现货价格
  1623. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  1624. OPERATESRC int32 `json:"operatesrc" xorm:"'OPERATESRC'"` // 最后操作来源 - 1:管理端 2:终端
  1625. OPERATEID int64 `json:"operateid" xorm:"'OPERATEID'"` // 最后操作人
  1626. OPERATETIME string `json:"operatetime" xorm:"'OPERATETIME'"` // 最后操作时间
  1627. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构id
  1628. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  1629. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  1630. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 现货商品单位id
  1631. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  1632. GMUNITID int32 `json:"gmunitid" xorm:"'GMUNITID'"` // 品类单位id
  1633. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货商品id
  1634. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货商品代码
  1635. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货商品名称
  1636. OPERATORNAME string `json:"operatorname"` // 操作人名称
  1637. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  1638. GBENUMDICNAME string `json:"gbenumdicname"` // 品类单位名称
  1639. }
  1640. func (r *Ermcp3SpotGoodsPriceLog) calc() {
  1641. if r.OPERATESRC == 1 {
  1642. r.OPERATORNAME = mtpcache.GetSystemmangerLoginCode(r.OPERATEID)
  1643. } else {
  1644. r.OPERATORNAME = mtpcache.GetLoginCodeByLoginId(r.OPERATEID)
  1645. }
  1646. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  1647. r.GBENUMDICNAME = mtpcache.GetEnumDicitemName(r.GMUNITID)
  1648. }
  1649. func (r *Ermcp3SpotGoodsPriceLog) buildSql() string {
  1650. var sqlId utils.SQLVal = "SELECT t.WRSTANDARDID," +
  1651. " t.SPOTGOODSBRANDID," +
  1652. " t.CURRENCYID," +
  1653. " t.SPOTGOODSPRICE," +
  1654. " t.TRADEDATE," +
  1655. " t.OPERATESRC," +
  1656. " t.OPERATEID," +
  1657. " to_char(t.OPERATETIME, 'yyyy-mm-dd hh24:mi:ss') OPERATETIME," +
  1658. " t.LOGID," +
  1659. " w.areauserid," +
  1660. " w.wrstandardcode," +
  1661. " w.wrstandardname," +
  1662. " w.unitid gmunitid," +
  1663. " gb.dgfactoryitemvalue brandname," +
  1664. " g.goodsunitid unitid ," +
  1665. " g.deliverygoodsid," +
  1666. " g.deliverygoodscode," +
  1667. " g.deliverygoodsname" +
  1668. " FROM ERMCP_SPOTGOODSPRICELOG t" +
  1669. " left join wrstandard w" +
  1670. " on t.wrstandardid = w.wrstandardid" +
  1671. " left join dgfactoryitem gb" +
  1672. " on t.spotgoodsbrandid = gb.dgfactoryitemid" +
  1673. " left join deliverygoods g" +
  1674. " on t.deliverygoodsid = g.deliverygoodsid" +
  1675. " WHERE 1 = 1"
  1676. sqlId.And("w.areauserid", r.AREAUSERID)
  1677. sqlId.And("t.deliverygoodsid", r.DELIVERYGOODSID)
  1678. return sqlId.String()
  1679. }
  1680. // GetDataEx 获取现货市价信息日志
  1681. func (r *Ermcp3SpotGoodsPriceLog) GetDataEx() (interface{}, error) {
  1682. sData := make([]Ermcp3SpotGoodsPriceLog, 0)
  1683. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1684. if err == nil {
  1685. for i := range sData {
  1686. sData[i].calc()
  1687. }
  1688. }
  1689. return sData, err
  1690. }
  1691. // Ermcp3HedgePlan 套保计划表结构
  1692. type Ermcp3HedgePlan struct {
  1693. Areauserid int64 `json:"areauserid" xorm:"'Areauserid'"` // 用户ID
  1694. Hedgeplanid string `json:"hedgeplanid" xorm:"'Hedgeplanid'"` // 套保计划ID(601+Unix秒时间戳(10位)+xxxxxx)
  1695. Hedgeplanno string `json:"hedgeplanno" xorm:"'Hedgeplanno'"` // 套保计划编号(名称)
  1696. Contracttype int `json:"contracttype" xorm:"'Contracttype'"` // 计划类型 - 1:采购 -1:销售
  1697. Deliverygoodsid int `json:"deliverygoodsid" xorm:"'Deliverygoodsid'"` // 现货品种ID
  1698. Deliverygoodsname string `json:"deliverygoodsname" xorm:"'Deliverygoodsname'"` // 现货品种名称
  1699. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  1700. Producttype int `json:"producttype" xorm:"'Producttype'"` // 产品类型 - 1:标准仓单 2:等标 3:非标
  1701. Spotgoodsdesc string `json:"spotgoodsdesc" xorm:"'Spotgoodsdesc'"` // 商品型号
  1702. Planqty float64 `json:"planqty" xorm:"'Planqty'"` // 计划数量
  1703. Convertfactor float64 `json:"convertfactor" xorm:"'Convertfactor'"` // 标仓系数
  1704. Plantime string `json:"plantime" xorm:"'Plantime'"` // 计划时间
  1705. Hedgeplanstatus int `json:"hedgeplanstatus" xorm:"'Hedgeplanstatus'"` // 套保计划状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
  1706. Remark string `json:"remark" xorm:"'Remark'"` // 备注
  1707. CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  1708. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  1709. AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
  1710. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位id
  1711. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  1712. }
  1713. func (r *Ermcp3HedgePlan) calc() {
  1714. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  1715. }
  1716. func (r *Ermcp3HedgePlan) buildSql(status string) string {
  1717. str := "select to_char(t.Hedgeplanid) Hedgeplanid," +
  1718. " t.Hedgeplanno," +
  1719. " t.Contracttype," +
  1720. " t.Deliverygoodsid," +
  1721. " g.Deliverygoodsname," +
  1722. " g.deliverygoodscode," +
  1723. " g.goodsunitid unitid," +
  1724. " t.Producttype," +
  1725. " t.Spotgoodsdesc," +
  1726. " t.Planqty," +
  1727. " t.Convertfactor," +
  1728. " to_char(t.Plantime, 'yyyy-mm-dd hh24:mi:ss') Plantime," +
  1729. " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
  1730. " to_char(t.updatetime, 'yyyy-mm-dd hh24:mi:ss') updatetime," +
  1731. " to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
  1732. " t.Hedgeplanstatus," +
  1733. " t.Remark" +
  1734. " from ermcp_hedgeplan t" +
  1735. " left join deliverygoods g" +
  1736. " on t.deliverygoodsid = g.deliverygoodsid" +
  1737. " where t.hedgeplanstatus in (%v)" +
  1738. " and t.areauserid = %v"
  1739. if status == "2" {
  1740. // 执行中状态,按审核时间倒序
  1741. str += " order by t.audittime desc"
  1742. } else {
  1743. str += " order by t.updatetime desc"
  1744. }
  1745. return fmt.Sprintf(str, status, r.Areauserid)
  1746. }
  1747. // GetData 从数据库中查询套保计划数据
  1748. func (r *Ermcp3HedgePlan) GetData(status string) ([]Ermcp3HedgePlan, error) {
  1749. e := db.GetEngine()
  1750. sData := make([]Ermcp3HedgePlan, 0)
  1751. if err := e.SQL(r.buildSql(status)).Find(&sData); err != nil {
  1752. logger.GetLogger().Errorf("query hedgeplan:%v", err)
  1753. return sData, err
  1754. }
  1755. for i := range sData {
  1756. sData[i].calc()
  1757. }
  1758. return sData, nil
  1759. }
  1760. // Ermcp3GoodsGroup 商品组
  1761. type Ermcp3GoodsGroup struct {
  1762. GOODSGROUPID int32 `json:"goodsgroupid" xorm:"'GOODSGROUPID'"` // 商品组ID(自增ID)
  1763. GOODSGROUPNAME string `json:"goodsgroupname" xorm:"'GOODSGROUPNAME'"` // 商品组名称
  1764. GOODSGROUPSTATUS int32 `json:"goodsgroupstatus" xorm:"'GOODSGROUPSTATUS'"` // 商品组状态 - 1:正常 2:注销
  1765. MARKETID int32 `json:"marketid" xorm:"'MARKETID'"` // 所属市场ID
  1766. CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  1767. CREATORID int32 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  1768. MODIFYTIME string `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  1769. MODIFIERID int32 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人
  1770. QUOTESOURCEGROUPID int64 `json:"quotesourcegroupid" xorm:"'QUOTESOURCEGROUPID'"` // 所属行情源分组ID[参考行情市场用\通道交易]
  1771. OUTERGROUPCODE string `json:"outergroupcode" xorm:"'OUTERGROUPCODE'"` // 外部商品组代码[通道交易]
  1772. CANSHORT int32 `json:"canshort" xorm:"'CANSHORT'"` // 是否允许做空[通道交易] - 0:不能做空 1:可以做空
  1773. EXEXCHANGEID int64 `json:"exexchangeid" xorm:"'EXEXCHANGEID'"` // 外部交易所ID[通道交易]
  1774. CURRENCYID int32 `json:"currencyid" xorm:"'CURRENCYID'"` // 报价货币ID
  1775. GOODUNITID int32 `json:"goodunitid" xorm:"'GOODUNITID'"` // 报价单位ID
  1776. AGREEUNIT float32 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  1777. DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  1778. QUOTEMINUNIT int32 `json:"quoteminunit" xorm:"'QUOTEMINUNIT'"` // 行情最小变动单位 [整数,报价小数位一起使用]
  1779. INNERDEALMODE int32 `json:"innerdealmode" xorm:"'INNERDEALMODE'"` // 内部成交方式[通道交易] - 1:净头寸 2:开平 3:平今
  1780. OUTERDEALMODE int32 `json:"outerdealmode" xorm:"'OUTERDEALMODE'"` // 外部成交方式[通道交易]- 1:净头寸 2:开平 3:平今
  1781. SYNCGOODSQTY int32 `json:"syncgoodsqty" xorm:"'SYNCGOODSQTY'"` // 同步合约数[通道交易-投资管理用] - 0表示不限
  1782. CLOSEPRICEMODE int32 `json:"closepricemode" xorm:"'CLOSEPRICEMODE'"` // 强平价格方式 - 1:市价 2:最新价 3:涨跌停(未实现)
  1783. GROUPCATEGROYID int32 `json:"groupcategroyid" xorm:"'GROUPCATEGROYID'"` // 品种分类ID
  1784. AreaUserId int64 `json:"areauserid" form:"areauserid" binding:"required"` // 所属机构id(套保品是有areauserid的,当要排除已配置商品组时需要areauserid过滤)
  1785. ExcludeCfg int32 `json:"excludecfg" form:"excludecfg"` // 排除套保品已配置期货分类下的商品组(但显示已配置商品组) 1-排除
  1786. }
  1787. func (r *Ermcp3GoodsGroup) calc() {
  1788. }
  1789. func (r *Ermcp3GoodsGroup) buildSql() string {
  1790. var sqlId utils.SQLVal = "SELECT t.GOODSGROUPID," +
  1791. " t.GOODSGROUPNAME," +
  1792. " t.GOODSGROUPSTATUS," +
  1793. " t.MARKETID," +
  1794. " to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  1795. " t.CREATORID," +
  1796. " to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
  1797. " t.MODIFIERID," +
  1798. " t.QUOTESOURCEGROUPID," +
  1799. " t.OUTERGROUPCODE," +
  1800. " t.CANSHORT," +
  1801. " t.EXEXCHANGEID," +
  1802. " t.CURRENCYID," +
  1803. " t.GOODUNITID," +
  1804. " t.AGREEUNIT," +
  1805. " t.DECIMALPLACE," +
  1806. " t.QUOTEMINUNIT," +
  1807. " t.INNERDEALMODE," +
  1808. " t.OUTERDEALMODE," +
  1809. " t.SYNCGOODSQTY," +
  1810. " t.CLOSEPRICEMODE," +
  1811. " t.GROUPCATEGROYID" +
  1812. " FROM GOODSGROUP t" +
  1813. " WHERE 1 = 1"
  1814. if r.ExcludeCfg == 1 {
  1815. str := "select t.goodsgroupid" +
  1816. " from ERMS_MiddleGoods t" +
  1817. " where t.isvalid=1 and t.areauserid = %v" +
  1818. "union all" +
  1819. "select goodsgroupid" +
  1820. " from goodsgroup t" +
  1821. " where t.groupcategroyid not in" +
  1822. " (select distinct g.groupcategroyid" +
  1823. " from erms_middlegoods t" +
  1824. " left join goodsgroup g" +
  1825. " on t.goodsgroupid = g.goodsgroupid" +
  1826. " where t.isvalid=1 and t.areauserid = %v)"
  1827. str = fmt.Sprintf(str, r.AreaUserId, r.AreaUserId)
  1828. sqlId.Join(fmt.Sprintf("and t.groupcategroyid not in(%v)", str))
  1829. }
  1830. return sqlId.String()
  1831. }
  1832. // GetData
  1833. func (r *Ermcp3GoodsGroup) GetData() ([]Ermcp3GoodsGroup, error) {
  1834. sData := make([]Ermcp3GoodsGroup, 0)
  1835. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1836. for i := range sData {
  1837. sData[i].calc()
  1838. }
  1839. return sData, err
  1840. }
  1841. // GetDataEx 商品组信息
  1842. func (r *Ermcp3GoodsGroup) GetDataEx() (interface{}, error) {
  1843. return r.GetData()
  1844. }