ermcp3.go 72 KB

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