ermcp3Report.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/4/16 18:22
  4. * @Modify : 2021/4/16 18:22
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/mtpcache"
  11. "mtp2_if/utils"
  12. )
  13. // Ermcp3ReportOPLog 报表合同操作记录通用查询
  14. type Ermcp3ReportOPLog struct {
  15. LOGID string `json:"logid" xorm:"'lOGID'"` // 流水ID(604+Unix秒时间戳(10位)+xxxxxx)
  16. BIZTYPE int32 `json:"biztype" xorm:"'BIZTYPE'"` // 业务类型 - 1:套保计划 2:现货合同
  17. OPERATELOGTYPE int32 `json:"operatelogtype" xorm:"'OPERATELOGTYPE'"` // 操作流水类型 -
  18. RELATEDID string `json:"relatedid" xorm:"'RELATEDID'"` // 现货合同ID\套保计划
  19. LOGVALUE string `json:"logvalue" xorm:"'LOGVALUE'"` // 数值
  20. LOGDATETIME string `json:"logdatetime" xorm:"'LOGDATETIME'"` // 流水日期(时间)
  21. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  22. APPLYID int64 `json:"applyid" xorm:"'APPLYID'"` // 操作人
  23. CONTRACTTYPE int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购 -1:销售
  24. USERID int64 `json:"userid" xorm:"'USERID'"` // 机构ID
  25. RELATEDNO string `json:"relatedno" xorm:"'RELATEDNO'"` // 合同编号
  26. UNITID int32 `json:"-" xorm:"'UNITID'"` // 现货商品单位id
  27. ENUMDICNAME string `json:"enumdicName"` // 单位名称
  28. OPTYPENAME string `json:"optypename"` // 流水类型名称
  29. LOGTYPENAME string `json:"logtypename"` // 合同类型(名称)
  30. APPLYNAME string `json:"applyname"` // 操作人名称
  31. BRANDNAME string `json:"brandname" xorm:"'brandname'"` // 品牌名称
  32. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  33. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  34. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  35. LogTypeFilter string `json:"-"` // 查询日志类型, 逗号隔开(如 1,2,4)
  36. }
  37. // Calc 处理数据
  38. func (r *Ermcp3ReportOPLog) Calc() {
  39. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  40. r.APPLYNAME = mtpcache.GetUserNameByUserId(r.APPLYID)
  41. if r.APPLYNAME == "" {
  42. // APPLYID 可能存的是loginId
  43. r.APPLYNAME = mtpcache.GetLoginCodeByLoginId(r.APPLYID)
  44. }
  45. //1:点价价格 2:点价数量 3:结算量 4:其它费用 5:追加保证金 6溢短金额 7:调整金额 8:付款金额 9:收款金额 10:退款金额
  46. //11:收票金额 12:开票金额 13:提交审核(合同) 14:审核通过(合同) 15:审核拒绝(合同) 16:合同撤回 17:提交审核(计划)
  47. //18:审核通过(计划) 19:审核拒绝(计划) 20:计划撤回 21:正常完结(合同) 22:异常终止(合同) 23:退还保证金
  48. // 数据库注释与返回值映身关系: 结算量->确定量, 收款->收款金额, 退款->退款金额, 付款->付款金额, 收票->收票金额, 开票->开票金额
  49. sDes := []string{"点价价格", "点价数量", "确定量", "其它费用", "追加保证金", "溢短金额", "调整金额", "付款", "收款", "退款",
  50. "收票", "开票", "提交审核(合同)", "审核通过(合同)", "审核拒绝(合同)", "合同撤回", "提交审核(计划)",
  51. "审核通过(计划)", "审核拒绝(计划)", "计划撤回", "正常完结(合同)", "异常终止(合同)", "退还保证金"}
  52. if r.OPERATELOGTYPE >= 1 && r.OPERATELOGTYPE <= 23 {
  53. r.OPTYPENAME = sDes[r.OPERATELOGTYPE-1]
  54. }
  55. // 收款款项:采购合同的退款、销售合同的收款应用正数显示,付款款项:采购合同的付款、销售合同的退款应用负数显示
  56. if r.CONTRACTTYPE == 1 {
  57. r.LOGTYPENAME = "采购"
  58. // 采购合同/退款 正数
  59. if r.OPERATELOGTYPE == 10 && len(r.LOGVALUE) > 0 {
  60. if r.LOGVALUE[0] == '-' {
  61. r.LOGVALUE = r.LOGVALUE[1:]
  62. }
  63. }
  64. // 采购合同/付款 负数
  65. if r.OPERATELOGTYPE == 8 && len(r.LOGVALUE) > 0 {
  66. if r.LOGVALUE[0] != '-' {
  67. r.LOGVALUE = "-" + r.LOGVALUE
  68. }
  69. }
  70. } else if r.CONTRACTTYPE == -1 {
  71. r.LOGTYPENAME = "销售"
  72. // 销售合同/收款 正数
  73. if r.OPERATELOGTYPE == 9 && len(r.LOGVALUE) > 0 {
  74. if r.LOGVALUE[0] == '-' {
  75. r.LOGVALUE = r.LOGVALUE[1:]
  76. }
  77. }
  78. // 销售合同/退款 负数
  79. if r.OPERATELOGTYPE == 10 && len(r.LOGVALUE) > 0 {
  80. if r.LOGVALUE[0] != '-' {
  81. r.LOGVALUE = "-" + r.LOGVALUE
  82. }
  83. }
  84. }
  85. // 去除多余的0,最后4个0
  86. if r.LOGVALUE[len(r.LOGVALUE)-4:] == "0000" {
  87. r.LOGVALUE = r.LOGVALUE[:len(r.LOGVALUE)-4]
  88. }
  89. if r.BIZTYPE == 1 {
  90. r.LOGTYPENAME += "计划"
  91. } else if r.BIZTYPE == 2 {
  92. r.LOGTYPENAME += "合同"
  93. }
  94. }
  95. func (r *Ermcp3ReportOPLog) buildSql() string {
  96. var sqlId utils.SQLVal = "SELECT to_char(t.LOGID) LOGID," +
  97. " t.BIZTYPE," +
  98. " t.OPERATELOGTYPE," +
  99. " to_char(t.RELATEDID) RELATEDID," +
  100. " t.LOGVALUE," +
  101. " to_char(t.LOGDATETIME, 'yyyy-mm-dd hh24:mi:ss') LOGDATETIME," +
  102. " t.TRADEDATE," +
  103. " t.APPLYID," +
  104. " t.CONTRACTTYPE," +
  105. " t.USERID," +
  106. " s.contractno relatedno," +
  107. " s.spotgoodsbrandid," +
  108. " g.deliverygoodsid," +
  109. " g.deliverygoodscode," +
  110. " g.deliverygoodsname," +
  111. " g.goodsunitid unitid," +
  112. " gb.dgfactoryitemvalue brandname" +
  113. " FROM ERMCP_CONTRACTOPERATELOG t" +
  114. " inner join ermcp_spotcontract s" +
  115. " on t.RELATEDID = s.spotcontractid" +
  116. " left join deliverygoods g" +
  117. " on t.deliverygoodsid = g.deliverygoodsid" +
  118. " left join dgfactoryitem gb" +
  119. " on s.spotgoodsbrandid = gb.dgfactoryitemid" +
  120. " WHERE t.biztype = 2"
  121. // 筛选条件
  122. sqlId.And("t.userid", r.USERID)
  123. sqlId.And("t.TRADEDATE", r.TRADEDATE)
  124. sqlId.AndEx("t.deliverygoodsid", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  125. if r.LogTypeFilter != "" {
  126. sqlId.Join(fmt.Sprintf(" and t.OPERATELOGTYPE in(%v)", r.LogTypeFilter))
  127. }
  128. return sqlId.String()
  129. }
  130. // GetDataEx 获取日志记录
  131. func (r *Ermcp3ReportOPLog) GetDataEx() (interface{}, error) {
  132. sData := make([]Ermcp3ReportOPLog, 0)
  133. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  134. for i := range sData {
  135. sData[i].Calc()
  136. }
  137. return sData, err
  138. }
  139. // Ermcp3ReportDaySpot 现货日报表
  140. type Ermcp3ReportDaySpot struct {
  141. BUYPRICEDQTY float64 `json:"-" xorm:"'BUYPRICEDQTY'"` // 期末采购定价量
  142. SELLPRICEDQTY float64 `json:"-" xorm:"'SELLPRICEDQTY'"` // 期末销售定价量
  143. ORIBUYPRICEDQTY float64 `json:"-" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购定价量
  144. ORISELLPRICEDQTY float64 `json:"-" xorm:"'ORISELLPRICEDQTY'"` // 期初销售定价量
  145. TODAYBUYRECKONQTY float64 `json:"todaybuyreckonqty" xorm:"'TODAYBUYRECKONQTY'"` // 采购确定量
  146. TODAYSELLRECKONQTY float64 `json:"todaysellreckonqty" xorm:"'TODAYSELLRECKONQTY'"` // 销售确定量
  147. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 日照时期(yyyyMMdd)
  148. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构T
  149. UNITID int32 `json:"-" xorm:"'UNITID'"` // 现货商品单位id
  150. BUYINQTY float64 `json:"buyinqty" xorm:"'BUYINQTY'"` // 采购入库量
  151. SELLOUTQTY float64 `json:"selloutqty" xorm:"'SELLOUTQTY'"` // 销售出库量
  152. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  153. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  154. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  155. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  156. TOTALBUYPRICEDQTY float64 `json:"totalbuypricedqty"` // 采购定价量 = 期末 - 期初
  157. TOTALSELLPRICEDQTY float64 `json:"totalsellpricedqty"` // 销售定价量 = 期末 - 期初
  158. BeginDate string `json:"-"` // 开始日期
  159. EndDate string `json:"-"` // 结束日期
  160. }
  161. // Calc 数据处理
  162. func (r *Ermcp3ReportDaySpot) Calc() {
  163. r.TOTALBUYPRICEDQTY = r.BUYPRICEDQTY - r.ORIBUYPRICEDQTY
  164. r.TOTALSELLPRICEDQTY = r.SELLPRICEDQTY - r.ORISELLPRICEDQTY
  165. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  166. }
  167. func (r *Ermcp3ReportDaySpot) buildSql() string {
  168. var sqlId utils.SQLVal = "with tmp as" +
  169. " (select t.userid," +
  170. " t.deliverygoodsid," +
  171. " t.reckondate," +
  172. " sum(t.todaybuyinqty) todaybuyinqty," +
  173. " sum(t.todayselloutqty) todayselloutqty" +
  174. " from Reckon_ERMCP_AreaStock t" +
  175. " group by t.userid, t.deliverygoodsid, t.reckondate)" +
  176. "select t.reckondate," +
  177. " t.BUYPRICEDQTY," +
  178. " t.SELLPRICEDQTY," +
  179. " t.Oribuypricedqty," +
  180. " t.Orisellpricedqty," +
  181. " t.TODAYBUYRECKONQTY," +
  182. " t.TODAYSELLRECKONQTY," +
  183. " t.RECKONDATE," +
  184. " t.AREAUSERID," +
  185. " g.deliverygoodsid," +
  186. " g.deliverygoodscode," +
  187. " g.deliverygoodsname," +
  188. " g.goodsunitid unitid," +
  189. " s.todaybuyinqty buyinqty," +
  190. " s.todayselloutqty selloutqty" +
  191. " from RECKON_ERMCP_AREASPOT t" +
  192. " left join tmp s" +
  193. " on t.reckondate = s.reckondate" +
  194. " and t.areauserid = s.userid" +
  195. " and t.deliverygoodsid = s.deliverygoodsid" +
  196. " left join deliverygoods g" +
  197. " on t.deliverygoodsid = g.deliverygoodsid" +
  198. " where 1 = 1"
  199. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  200. if r.DELIVERYGOODSID > 0 {
  201. sqlId.And("t.DELIVERYGOODSID", r.DELIVERYGOODSID)
  202. }
  203. if r.RECKONDATE != "" {
  204. sqlId.And("t.RECKONDATE", r.RECKONDATE)
  205. } else if r.BeginDate != "" && r.BeginDate == r.EndDate {
  206. sqlId.And("t.RECKONDATE", r.BeginDate)
  207. } else {
  208. if r.BeginDate != "" {
  209. sqlId.BiggerOrEq("t.RECKONDATE", r.BeginDate)
  210. }
  211. if r.EndDate != "" {
  212. sqlId.LessOrEq("t.RECKONDATE", r.EndDate)
  213. }
  214. }
  215. sqlId.Join(" order by t.RECKONDATE")
  216. return sqlId.String()
  217. }
  218. // GetDataEx 获取现货日报表
  219. func (r *Ermcp3ReportDaySpot) GetDataEx() (interface{}, error) {
  220. sData := make([]Ermcp3ReportDaySpot, 0)
  221. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  222. for i := range sData {
  223. sData[i].Calc()
  224. }
  225. return sData, err
  226. }
  227. // Ermcp3ReportMonSpot 现货月报表
  228. type Ermcp3ReportMonSpot struct {
  229. CYCLETYPE int32 `json:"cycletype" xorm:"'cycletype'"` // 周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】
  230. CYCLETIME string `json:"cycletime" xorm:"'cycletime'"` // 周期时间 月(YYYYMM) 季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)【原值】
  231. BUYPRICEDQTY float64 `json:"-" xorm:"'BUYPRICEDQTY'"` // 期末采购定价量
  232. SELLPRICEDQTY float64 `json:"-" xorm:"'SELLPRICEDQTY'"` // 期末销售定价量
  233. ORIBUYPRICEDQTY float64 `json:"-" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购定价量
  234. ORISELLPRICEDQTY float64 `json:"-" xorm:"'ORISELLPRICEDQTY'"` // 期初销售定价量
  235. TODAYBUYRECKONQTY float64 `json:"todaybuyreckonqty" xorm:"'TODAYBUYRECKONQTY'"` // 采购确定量
  236. TODAYSELLRECKONQTY float64 `json:"todaysellreckonqty" xorm:"'TODAYSELLRECKONQTY'"` // 销售确定量
  237. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构id
  238. UNITID int32 `json:"-" xorm:"'UNITID'"` // 现货商品单位id
  239. BUYINQTY float64 `json:"buyinqty" xorm:"'BUYINQTY'"` // 采购入库量
  240. SELLOUTQTY float64 `json:"selloutqty" xorm:"'SELLOUTQTY'"` // 销售出库量
  241. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  242. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  243. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  244. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  245. TOTALBUYPRICEDQTY float64 `json:"totalbuypricedqty"` // 采购定价量 = 期末 - 期初
  246. TOTALSELLPRICEDQTY float64 `json:"totalsellpricedqty"` // 销售定价量 = 期末 - 期初
  247. }
  248. // Calc 数据处理
  249. func (r *Ermcp3ReportMonSpot) Calc() {
  250. r.TOTALBUYPRICEDQTY = r.BUYPRICEDQTY - r.ORIBUYPRICEDQTY
  251. r.TOTALSELLPRICEDQTY = r.SELLPRICEDQTY - r.ORISELLPRICEDQTY
  252. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  253. }
  254. func (r *Ermcp3ReportMonSpot) buildSql() string {
  255. var sqlId utils.SQLVal = "with tmp as" +
  256. " (select t.userid," +
  257. " t.deliverygoodsid," +
  258. " t.cycletime," +
  259. " t.cycletype," +
  260. " sum(t.todaybuyinqty) todaybuyinqty," +
  261. " sum(t.todayselloutqty) todayselloutqty" +
  262. " from Report_ERMCP_AreaStock t" +
  263. " group by t.userid, t.deliverygoodsid, t.cycletime, t.cycletype)" +
  264. "select t.BUYPRICEDQTY," +
  265. " t.SELLPRICEDQTY," +
  266. " t.Oribuypricedqty," +
  267. " t.Orisellpricedqty," +
  268. " t.TODAYBUYRECKONQTY," +
  269. " t.TODAYSELLRECKONQTY," +
  270. " t.cycletype," +
  271. " t.cycletime," +
  272. " t.AREAUSERID," +
  273. " g.deliverygoodsid," +
  274. " g.deliverygoodscode," +
  275. " g.deliverygoodsname," +
  276. " g.goodsunitid unitid," +
  277. " s.todaybuyinqty buyinqty," +
  278. " s.todayselloutqty selloutqty" +
  279. " from Report_ERMCP_AreaSpot t" +
  280. " left join tmp s" +
  281. " on t.cycletime = s.cycletime" +
  282. " and t.cycletype = s.cycletype" +
  283. " and t.areauserid = s.userid" +
  284. " and t.deliverygoodsid = s.deliverygoodsid" +
  285. " left join deliverygoods g" +
  286. " on t.deliverygoodsid = g.deliverygoodsid" +
  287. " where t.cycletype = 1"
  288. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  289. sqlId.And("t.cycletime", r.CYCLETIME)
  290. return sqlId.String()
  291. }
  292. // GetDataEx 获取现货月报表
  293. func (r *Ermcp3ReportMonSpot) GetDataEx() (interface{}, error) {
  294. sData := make([]Ermcp3ReportMonSpot, 0)
  295. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  296. for i := range sData {
  297. sData[i].Calc()
  298. }
  299. return sData, err
  300. }
  301. // Ermcp3ReportAreaSpotPL 现货损益日/月表
  302. type Ermcp3ReportAreaSpotPL struct {
  303. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  304. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类ID
  305. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID
  306. ORIBUYQTY float64 `json:"oribuyqty" xorm:"'ORIBUYQTY'"` // 期初采购总量
  307. ORIBUYAMOUNT float64 `json:"oribuyamount" xorm:"'ORIBUYAMOUNT'"` // 期初采购总额
  308. ORISELLQTY float64 `json:"orisellqty" xorm:"'ORISELLQTY'"` // 期初销售总量
  309. ORISELLAMOUNT float64 `json:"orisellamount" xorm:"'ORISELLAMOUNT'"` // 期初销售总额
  310. ORIQTY float64 `json:"oriqty" xorm:"'ORIQTY'"` // 期初量
  311. ORIAVERAGEPRICE float64 `json:"oriaverageprice" xorm:"'ORIAVERAGEPRICE'"` // 期初均价
  312. ORIAMOUNT float64 `json:"oriamount" xorm:"'ORIAMOUNT'"` // 期初额
  313. TODAYBUYQTY float64 `json:"todaybuyqty" xorm:"'TODAYBUYQTY'"` // 今日采购量(采购增量)
  314. TODAYBUYAMOUNT float64 `json:"todaybuyamount" xorm:"'TODAYBUYAMOUNT'"` // 今日采购额
  315. TODAYBUYAVERAGEPRICE float64 `json:"todaybuyaverageprice" xorm:"'TODAYBUYAVERAGEPRICE'"` // 今日采购均价(采购均价)
  316. TODAYSELLQTY float64 `json:"todaysellqty" xorm:"'TODAYSELLQTY'"` // 今日销售量(销售增量)
  317. TODAYSELLAMOUNT float64 `json:"todaysellamount" xorm:"'TODAYSELLAMOUNT'"` // 今日销售额
  318. TODAYSELLAVERAGEPRICE float64 `json:"todaysellaverageprice" xorm:"'TODAYSELLAVERAGEPRICE'"` // 今日销售均价(销售均价)
  319. CURBUYQTY float64 `json:"curbuyqty" xorm:"'CURBUYQTY'"` // 期末采购总量
  320. CURBUYAMOUNT float64 `json:"curbuyamount" xorm:"'CURBUYAMOUNT'"` // 期末采购总额(采购额)
  321. CURSELLQTY float64 `json:"cursellqty" xorm:"'CURSELLQTY'"` // 期末销售总量
  322. CURSELLAMOUNT float64 `json:"cursellamount" xorm:"'CURSELLAMOUNT'"` // 期末销售总额(销售额)
  323. CURQTY float64 `json:"curqty" xorm:"'CURQTY'"` // 期末量
  324. CURAVERAGEPRICE float64 `json:"curaverageprice" xorm:"'CURAVERAGEPRICE'"` // 期末均价
  325. CURAMOUNT float64 `json:"curamount" xorm:"'CURAMOUNT'"` // 期末额
  326. CURSPOTPRICE float64 `json:"curspotprice" xorm:"'CURSPOTPRICE'"` // 参考市价
  327. CURMARKETVALUE float64 `json:"curmarketvalue" xorm:"'CURMARKETVALUE'"` // 参考市值
  328. ACTUALPL float64 `json:"actualpl" xorm:"'ACTUALPL'"` // 实际损益
  329. FLOATPL float64 `json:"floatpl" xorm:"'FLOATPL'"` // 浮动损益
  330. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  331. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  332. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  333. WRUNITID int32 `json:"unitid" xorm:"'UNITID'"` // 品类单位id
  334. BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
  335. MODELNAME string `json:"modelname" xorm:"'MODELNAME'"` // 品类名称
  336. GBUNITID int32 `json:"gbunitid" xorm:"'GBUNITID'"` // 现货单位id
  337. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
  338. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  339. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  340. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  341. WRENUMDICNAME string `json:"gbenumdicname"` // 品类单位名称
  342. ReportType int32 `json:"-"` // 报表类型 1-日报表 2-月报表
  343. ReportDate string `json:"-"` // 格式 日报表(YYYYMMDD) 月报表(YYYYMM)
  344. }
  345. func (r *Ermcp3ReportAreaSpotPL) calc() {
  346. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GBUNITID)
  347. r.WRENUMDICNAME = mtpcache.GetEnumDicitemName(r.WRUNITID)
  348. }
  349. func (r *Ermcp3ReportAreaSpotPL) buildSql() string {
  350. var sqlId utils.SQLVal = "SELECT t.AREAUSERID," +
  351. " t.WRSTANDARDID," +
  352. " t.SPOTGOODSBRANDID," +
  353. " t.ORIBUYQTY," +
  354. " t.ORIBUYAMOUNT," +
  355. " t.ORISELLQTY," +
  356. " t.ORISELLAMOUNT," +
  357. " t.ORIQTY," +
  358. " t.ORIAVERAGEPRICE," +
  359. " t.ORIAMOUNT," +
  360. " t.TODAYBUYQTY," +
  361. " t.TODAYBUYAMOUNT," +
  362. " t.TODAYBUYAVERAGEPRICE," +
  363. " t.TODAYSELLQTY," +
  364. " t.TODAYSELLAMOUNT," +
  365. " t.TODAYSELLAVERAGEPRICE," +
  366. " t.CURBUYQTY," +
  367. " t.CURBUYAMOUNT," +
  368. " t.CURSELLQTY," +
  369. " t.CURSELLAMOUNT," +
  370. " t.CURQTY," +
  371. " t.CURAVERAGEPRICE," +
  372. " t.CURAMOUNT," +
  373. " t.CURSPOTPRICE," +
  374. " t.CURMARKETVALUE," +
  375. " t.ACTUALPL," +
  376. " t.FLOATPL," +
  377. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
  378. " w.wrstandardcode," +
  379. " w.wrstandardname," +
  380. " w.unitid WRUNITID," +
  381. " gb.dgfactoryitemvalue brandname," +
  382. " g.deliverygoodsid," +
  383. " g.deliverygoodscode," +
  384. " g.deliverygoodsname," +
  385. " g.goodsunitid GBUNITID" +
  386. " FROM %v t" +
  387. " left join deliverygoods g" +
  388. " on t.deliverygoodsid = g.deliverygoodsid" +
  389. " left join wrstandard w" +
  390. " on t.wrstandardid = w.wrstandardid" +
  391. " left join dgfactoryitem gb" +
  392. " on t.spotgoodsbrandid = gb.dgfactoryitemid" +
  393. " WHERE 1 = 1"
  394. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  395. if r.ReportType == 1 {
  396. // 日报表
  397. sqlId.FormatParam("RECKON_ERMCP_AREASPOTPL")
  398. sqlId.And("t.reckondate", r.ReportDate)
  399. } else {
  400. // 月报表
  401. sqlId.FormatParam("REPORT_ERMCP_AREASPOTPL")
  402. sqlId.And("t.cycletype", 1)
  403. sqlId.And("t.cycletime", r.ReportDate)
  404. }
  405. if r.WRSTANDARDID > 0 {
  406. sqlId.And("t.wrstandardid", r.WRSTANDARDID)
  407. }
  408. if r.SPOTGOODSBRANDID > 0 {
  409. sqlId.And("t.spotgoodsbrandid", r.SPOTGOODSBRANDID)
  410. }
  411. if r.DELIVERYGOODSID > 0 {
  412. sqlId.And("t.deliverygoodsid", r.DELIVERYGOODSID)
  413. }
  414. return sqlId.String()
  415. }
  416. // GetDataEx 获取现货损益日(月)报表
  417. func (r *Ermcp3ReportAreaSpotPL) GetDataEx() (interface{}, error) {
  418. sData := make([]Ermcp3ReportAreaSpotPL, 0)
  419. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  420. for i := range sData {
  421. sData[i].calc()
  422. }
  423. return sData, err
  424. }