ermcpReport.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/2/4 11:27
  4. * @Modify : 2021/2/4 11:27
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/mtpcache"
  11. "mtp2_if/utils"
  12. )
  13. // ErmcpReportDayFR 财务日报表
  14. type ErmcpReportDayFR struct {
  15. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 日照时期(yyyyMMdd)
  16. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  17. COLLECTMONEYCOUNT int32 `json:"collectmoneycount" xorm:"'COLLECTMONEYCOUNT'"` // 今日收款笔数
  18. COLLECTMONEYAMOUNT float64 `json:"collectmoneyamount" xorm:"'COLLECTMONEYAMOUNT'"` // 今日收款金额
  19. PAYMONEYCOUNT int32 `json:"paymoneycount" xorm:"'PAYMONEYCOUNT'"` // 今日付款笔数
  20. PAYMONEYAMOUNT float64 `json:"paymoneyamount" xorm:"'PAYMONEYAMOUNT'"` // 今日付款金额
  21. COLLECTINVOICECOUNT int32 `json:"collectinvoicecount" xorm:"'COLLECTINVOICECOUNT'"` // 今日开票笔数
  22. COLLECTINVOICEAMOUNT float64 `json:"collectinvoiceamount" xorm:"'COLLECTINVOICEAMOUNT'"` // 今日开票金额
  23. PAYINVOICECOUNT int32 `json:"payinvoicecount" xorm:"'PAYINVOICECOUNT'"` // 今日收票笔数
  24. PAYINVOICEAMOUNT float64 `json:"payinvoiceamount" xorm:"'PAYINVOICEAMOUNT'"` // 今日收票金额
  25. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  26. BeginDate string `json:"-"` // 开始日期
  27. EndDate string `json:"-"` // 结束日期
  28. }
  29. // Calc 数据处理
  30. func (r *ErmcpReportDayFR) Calc() {
  31. }
  32. func (r *ErmcpReportDayFR) buildSql() string {
  33. var sqlId utils.SQLVal = "SELECT t.RECKONDATE," +
  34. " t.AREAUSERID," +
  35. " t.COLLECTMONEYCOUNT," +
  36. " t.COLLECTMONEYAMOUNT," +
  37. " t.PAYMONEYCOUNT," +
  38. " t.PAYMONEYAMOUNT," +
  39. " t.COLLECTINVOICECOUNT," +
  40. " t.COLLECTINVOICEAMOUNT," +
  41. " t.PAYINVOICECOUNT," +
  42. " t.PAYINVOICEAMOUNT," +
  43. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh:mi:ss') UPDATETIME" +
  44. " FROM RECKON_ERMCP_AREAFR t" +
  45. " WHERE 1 = 1"
  46. // 查询条件
  47. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  48. if r.RECKONDATE != "" {
  49. sqlId.And("t.RECKONDATE", r.RECKONDATE)
  50. } else if r.BeginDate != "" && r.BeginDate == r.EndDate {
  51. sqlId.And("t.RECKONDATE", r.BeginDate)
  52. } else {
  53. if r.BeginDate != "" {
  54. sqlId.BiggerOrEq("t.RECKONDATE", r.BeginDate)
  55. }
  56. if r.EndDate != "" {
  57. sqlId.LessOrEq("t.RECKONDATE", r.EndDate)
  58. }
  59. }
  60. return sqlId.String()
  61. }
  62. // GetDataEx 获取日报表
  63. func (r *ErmcpReportDayFR) GetDataEx() (interface{}, error) {
  64. sData := make([]ErmcpReportDayFR, 0)
  65. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  66. return sData, err
  67. }
  68. // ErmcpReportDayFRKx 财务日报表/款项
  69. type ErmcpReportDayFRKx struct {
  70. USERID int64 `json:"userid" xorm:"'USERID'"` // 机构ID
  71. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  72. }
  73. // GetDataEx 获取日报表款项记录
  74. func (r *ErmcpReportDayFRKx) GetDataEx() (interface{}, error) {
  75. m := ErmcpReportOPLog{USERID: r.USERID, LogTypeFilter: "8,9,10", TRADEDATE: r.TRADEDATE}
  76. return m.GetDataEx()
  77. }
  78. // ErmcpReportOPLog 报表合同操作记录通用查询
  79. type ErmcpReportOPLog struct {
  80. LOGID string `json:"logid" xorm:"'lOGID'"` // 流水ID(604+Unix秒时间戳(10位)+xxxxxx)
  81. BIZTYPE int32 `json:"biztype" xorm:"'BIZTYPE'"` // 业务类型 - 1:套保计划 2:现货合同
  82. OPERATELOGTYPE int32 `json:"operatelogtype" xorm:"'OPERATELOGTYPE'"` // 操作流水类型 -
  83. RELATEDID string `json:"relatedid" xorm:"'RELATEDID'"` // 现货合同ID\套保计划
  84. LOGVALUE string `json:"logvalue" xorm:"'LOGVALUE'"` // 数值
  85. LOGDATETIME string `json:"logdatetime" xorm:"'LOGDATETIME'"` // 流水日期(时间)
  86. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  87. APPLYID int64 `json:"applyid" xorm:"'APPLYID'"` // 操作人
  88. CONTRACTTYPE int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购 -1:销售
  89. USERID int64 `json:"userid" xorm:"'USERID'"` // 机构ID
  90. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
  91. RELATEDNO string `json:"relatedno" xorm:"'RELATEDNO'"` // 合同编号
  92. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
  93. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
  94. UNITID int32 `json:"-" xorm:"'UNITID'"` // 现货商品单位id
  95. ENUMDICNAME string `json:"enumdicName"` // 单位名称
  96. OPTYPENAME string `json:"optypename"` // 流水类型名称
  97. LOGTYPENAME string `json:"logtypename"` // 合同类型(名称)
  98. APPLYNAME string `json:"applyname"` // 操作人名称
  99. LogTypeFilter string `json:"-"` // 查询日志类型, 逗号隔开(如 1,2,4)
  100. }
  101. // Calc 处理数据
  102. func (r *ErmcpReportOPLog) Calc() {
  103. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  104. r.APPLYNAME = mtpcache.GetUserNameByUserId(r.APPLYID)
  105. if r.APPLYNAME == "" {
  106. // APPLYID 可能存的是loginId
  107. r.APPLYNAME = mtpcache.GetLoginCodeByLoginId(r.APPLYID)
  108. }
  109. //1:点价价格 2:点价数量 3:结算量 4:其它费用 5:追加保证金 6溢短金额 7:调整金额 8:付款金额 9:收款金额 10:退款金额
  110. //11:收票金额 12:开票金额 13:提交审核(合同) 14:审核通过(合同) 15:审核拒绝(合同) 16:合同撤回 17:提交审核(计划)
  111. //18:审核通过(计划) 19:审核拒绝(计划) 20:计划撤回 21:正常完结(合同) 22:异常终止(合同) 23:退还保证金
  112. // 数据库注释与返回值映身关系: 结算量->确定量, 收款->收款金额, 退款->退款金额, 付款->付款金额, 收票->收票金额, 开票->开票金额
  113. sDes := []string{"点价价格", "点价数量", "确定量", "其它费用", "追加保证金", "溢短金额", "调整金额", "付款", "收款", "退款",
  114. "收票", "开票", "提交审核(合同)", "审核通过(合同)", "审核拒绝(合同)", "合同撤回", "提交审核(计划)",
  115. "审核通过(计划)", "审核拒绝(计划)", "计划撤回", "正常完结(合同)", "异常终止(合同)", "退还保证金"}
  116. if r.OPERATELOGTYPE >= 1 && r.OPERATELOGTYPE <= 23 {
  117. r.OPTYPENAME = sDes[r.OPERATELOGTYPE-1]
  118. }
  119. // 收款款项:采购合同的退款、销售合同的收款应用正数显示,付款款项:采购合同的付款、销售合同的退款应用负数显示
  120. if r.CONTRACTTYPE == 1 {
  121. r.LOGTYPENAME = "采购"
  122. // 采购合同/退款 正数
  123. if r.OPERATELOGTYPE == 10 && len(r.LOGVALUE) > 0 {
  124. if r.LOGVALUE[0] == '-' {
  125. r.LOGVALUE = r.LOGVALUE[1:]
  126. }
  127. }
  128. // 采购合同/付款 负数
  129. if r.OPERATELOGTYPE == 8 && len(r.LOGVALUE) > 0 {
  130. if r.LOGVALUE[0] != '-' {
  131. r.LOGVALUE = "-" + r.LOGVALUE
  132. }
  133. }
  134. } else if r.CONTRACTTYPE == -1 {
  135. r.LOGTYPENAME = "销售"
  136. // 销售合同/收款 正数
  137. if r.OPERATELOGTYPE == 9 && len(r.LOGVALUE) > 0 {
  138. if r.LOGVALUE[0] == '-' {
  139. r.LOGVALUE = r.LOGVALUE[1:]
  140. }
  141. }
  142. // 销售合同/退款 负数
  143. if r.OPERATELOGTYPE == 10 && len(r.LOGVALUE) > 0 {
  144. if r.LOGVALUE[0] != '-' {
  145. r.LOGVALUE = "-" + r.LOGVALUE
  146. }
  147. }
  148. }
  149. if r.BIZTYPE == 1 {
  150. r.LOGTYPENAME += "计划"
  151. } else if r.BIZTYPE == 2 {
  152. r.LOGTYPENAME += "合同"
  153. }
  154. }
  155. func (r *ErmcpReportOPLog) buildSql() string {
  156. var sqlId utils.SQLVal = "with tmp as" +
  157. " (select to_char(t.hedgeplanid) relatedid," +
  158. " t.hedgeplanno relatedno," +
  159. " 1 as logType," +
  160. " t.contracttype" +
  161. " from ermcp_hedgeplan t" +
  162. " where t.areauserid = %v" +
  163. " union all" +
  164. " select to_char(t.spotcontractid)," +
  165. " t.contractno," +
  166. " 2 as logType," +
  167. " t.contracttype" +
  168. " from ermcp_spotcontract t" +
  169. " where t.userid = %v)" +
  170. " SELECT to_char(t.LOGID) LOGID," +
  171. " t.BIZTYPE," +
  172. " t.OPERATELOGTYPE," +
  173. " to_char(t.RELATEDID) RELATEDID," +
  174. " t.LOGVALUE," +
  175. " to_char(t.LOGDATETIME, 'yyyy-mm-dd hh24:mi:ss') LOGDATETIME," +
  176. " t.TRADEDATE," +
  177. " t.APPLYID," +
  178. " t.CONTRACTTYPE," +
  179. " t.USERID," +
  180. " t.WRSTANDARDID," +
  181. " tmp.relatedno," +
  182. " w.wrstandardname," +
  183. " w.wrstandardcode," +
  184. " w.unitid" +
  185. " FROM ERMCP_CONTRACTOPERATELOG t" +
  186. " inner join tmp" +
  187. " on t.RELATEDID = tmp.RELATEDID" +
  188. " and t.userid = %v" +
  189. " left join wrstandard w on t.wrstandardid=w.wrstandardid" +
  190. " WHERE 1 = 1"
  191. sqlId = utils.SQLVal(fmt.Sprintf(sqlId.String(), r.USERID, r.USERID, r.USERID))
  192. // 筛选条件
  193. sqlId.And("t.TRADEDATE", r.TRADEDATE)
  194. if r.WRSTANDARDID > 0 {
  195. sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
  196. }
  197. if r.LogTypeFilter != "" {
  198. sqlId.Join(fmt.Sprintf(" and t.OPERATELOGTYPE in(%v)", r.LogTypeFilter))
  199. }
  200. return sqlId.String()
  201. }
  202. // GetDataEx 获取日志记录
  203. func (r *ErmcpReportOPLog) GetDataEx() (interface{}, error) {
  204. sData := make([]ErmcpReportOPLog, 0)
  205. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  206. for i := range sData {
  207. sData[i].Calc()
  208. }
  209. return sData, err
  210. }
  211. // ErmcpReportMonthFR 财务月报表
  212. type ErmcpReportMonthFR struct {
  213. CYCLETYPE int32 `json:"cycletype" xorm:"'cycletype'"` // 周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】
  214. CYCLETIME string `json:"cycletime" xorm:"'cycletime'"` // 周期时间 月(YYYYMM) 季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)【原值】
  215. AREAUSERID int64 `json:"areauserid" xorm:"'areauserid'"` // 所属机构【原值】
  216. COLLECTMONEYCOUNT int32 `json:"collectmoneycount" xorm:"'collectmoneycount'"` // 今日收款笔数 【汇总】
  217. COLLECTMONEYAMOUNT float64 `json:"collectmoneyamount" xorm:"'collectmoneyamount'"` // 今日收款金额【汇总】
  218. PAYMONEYCOUNT int32 `json:"paymoneycount" xorm:"'paymoneycount'"` // 今日付款笔数【汇总】
  219. PAYMONEYAMOUNT float64 `json:"paymoneyamount" xorm:"'paymoneyamount'"` // 今日付款金额【汇总】
  220. COLLECTINVOICECOUNT int32 `json:"collectinvoicecount" xorm:"'collectinvoicecount'"` // 今日开票笔数【汇总】
  221. COLLECTINVOICEAMOUNT float64 `json:"collectinvoiceamount" xorm:"'collectinvoiceamount'"` // 今日开票金额【汇总】
  222. PAYINVOICECOUNT int32 `json:"payinvoicecount" xorm:"'payinvoicecount'"` // 今日收票笔数【汇总】
  223. PAYINVOICEAMOUNT float64 `json:"payinvoiceamount" xorm:"'payinvoiceamount'"` // 今日收票金额【汇总】
  224. UPDATETIME string `json:"updatetime" xorm:"'updatetime'"` // 更新时间
  225. DayFR []ErmcpReportDayFR `json:"dayFr"` // 日报表明细
  226. }
  227. // Calc 数据处理
  228. func (r *ErmcpReportMonthFR) Calc() {
  229. }
  230. func (r *ErmcpReportMonthFR) buildSql() string {
  231. var sqlId utils.SQLVal = "SELECT t.CYCLETYPE," +
  232. " t.CYCLETIME," +
  233. " t.AREAUSERID," +
  234. " t.COLLECTMONEYCOUNT," +
  235. " t.COLLECTMONEYAMOUNT," +
  236. " t.PAYMONEYCOUNT," +
  237. " t.PAYMONEYAMOUNT," +
  238. " t.COLLECTINVOICECOUNT," +
  239. " t.COLLECTINVOICEAMOUNT," +
  240. " t.PAYINVOICECOUNT," +
  241. " t.PAYINVOICEAMOUNT," +
  242. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh:mi:ss') UPDATETIME" +
  243. " FROM REPORT_ERMCP_AREAFR t" +
  244. " WHERE 1 = 1"
  245. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  246. sqlId.And("t.CYCLETYPE", 1)
  247. sqlId.And("t.CYCLETIME", r.CYCLETIME)
  248. return sqlId.String()
  249. }
  250. // GetDataEx 获取月报表
  251. func (r *ErmcpReportMonthFR) GetDataEx() (interface{}, error) {
  252. sData := make([]ErmcpReportMonthFR, 0)
  253. // 月报表
  254. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  255. // 日报表明细
  256. if len(r.CYCLETIME) != 6 {
  257. // 月报表的日期应是6位,如 202101
  258. return nil, nil
  259. }
  260. t1 := r.CYCLETIME + "01"
  261. t2 := r.CYCLETIME + "31"
  262. for i := range sData {
  263. sData[i].Calc()
  264. dayM := ErmcpReportDayFR{AREAUSERID: r.AREAUSERID, BeginDate: t1, EndDate: t2}
  265. if dObj, err := dayM.GetDataEx(); err == nil {
  266. if d, ok := dObj.([]ErmcpReportDayFR); ok {
  267. sData[i].DayFR = d
  268. }
  269. }
  270. }
  271. return sData, err
  272. }
  273. // ErmcpReportDayExposure 敞口日报表
  274. type ErmcpReportDayExposure struct {
  275. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 日照时期(yyyyMMdd)
  276. MIDDLEGOODSID int64 `json:"middlegoodsid" xorm:"'MIDDLEGOODSID'"` // 套保品种ID
  277. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  278. ORIBUYPLANQTY float64 `json:"oribuyplanqty" xorm:"'ORIBUYPLANQTY'"` // 期初采购计划数量
  279. ORIBUYPRICEDQTY float64 `json:"oribuypricedqty" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购合同已定价数量
  280. ORISELLPLANQTY float64 `json:"orisellplanqty" xorm:"'ORISELLPLANQTY'"` // 期初销售计划数量
  281. ORISELLPRICEDQTY float64 `json:"orisellpricedqty" xorm:"'ORISELLPRICEDQTY'"` // 期初销售合同已定价数量
  282. ORIBUYFUTUREQTY float64 `json:"oribuyfutureqty" xorm:"'ORIBUYFUTUREQTY'"` // 期初买入期货数量
  283. ORISELLFUTUREQTY float64 `json:"orisellfutureqty" xorm:"'ORISELLFUTUREQTY'"` // 期初卖出期货数量
  284. BUYPLANQTY float64 `json:"buyplanqty" xorm:"'BUYPLANQTY'"` // 采购计划数量
  285. BUYPRICEDQTY float64 `json:"buypricedqty" xorm:"'BUYPRICEDQTY'"` // 采购合同已定价数量
  286. SELLPLANQTY float64 `json:"sellplanqty" xorm:"'SELLPLANQTY'"` // 销售计划数量
  287. SELLPRICEDQTY float64 `json:"sellpricedqty" xorm:"'SELLPRICEDQTY'"` // 销售合同已定价数量
  288. BUYFUTUREQTY float64 `json:"buyfutureqty" xorm:"'BUYFUTUREQTY'"` // 买入期货数量
  289. SELLFUTUREQTY float64 `json:"sellfutureqty" xorm:"'SELLFUTUREQTY'"` // 卖出期货数量
  290. TOTALSPOTQTY float64 `json:"totalspotqty" xorm:"'TOTALSPOTQTY'"` // 现货数量
  291. TOTALFUTUREQTY float64 `json:"totalfutureqty" xorm:"'TOTALFUTUREQTY'"` // 期货数量
  292. TOTALEXPOSURE float64 `json:"totalexposure" xorm:"'TOTALEXPOSURE'"` // 总敞口
  293. TOTALHEDGERATIO float64 `json:"totalhedgeratio" xorm:"'TOTALHEDGERATIO'"` // 敞口比例
  294. TOTALNEEDHEDGEQTY float64 `json:"totalneedhedgeqty" xorm:"'TOTALNEEDHEDGEQTY'"` // 期货应套保量
  295. NEEDHEDGEEXPOSOURE float64 `json:"needhedgeexposoure" xorm:"'NEEDHEDGEEXPOSOURE'"` // 应套保敞口
  296. NEEDHEDGERATIO float64 `json:"needhedgeratio" xorm:"'NEEDHEDGERATIO'"` // 应套保敞口比例
  297. MIDDLEGOODSNAME string `json:"middlegoodsname" xorm:"'MIDDLEGOODSNAME'"` // 套保品种名称
  298. MIDDLEGOODSCODE string `json:"middlegoodscode" xorm:"'MIDDLEGOODSCODE'"` // 套保品种代码
  299. MIDDLEGOODSHEDGERATIO float64 `json:"middlegoodshedgeratio" xorm:"'MIDDLEGOODSHEDGERATIO'"` // 应套保比例
  300. GOODSUNITID int32 `json:"-" xorm:"'GOODSUNITID'"` // 套保商品单位id
  301. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  302. OriTotalSpotQty float64 `json:"oriTotalSpotQty"` // 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
  303. OriTotalFutuQty float64 `json:"oriTotalFutuQty"` // 期初期货数量=期初买入期货数量-期初卖出期货数量
  304. DiffSpotQty float64 `json:"diffSpotQty"` // 今日变动量(现货) = 现货数量 - 期初现货数量
  305. DiffFutuQty float64 `json:"diffFutuQty"` // 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
  306. }
  307. // Calc 数据处理
  308. func (r *ErmcpReportDayExposure) Calc() {
  309. r.OriTotalSpotQty = (r.ORISELLPLANQTY - r.ORISELLPRICEDQTY) - (r.ORIBUYPLANQTY - r.ORIBUYPRICEDQTY)
  310. r.OriTotalFutuQty = r.ORIBUYFUTUREQTY - r.ORISELLFUTUREQTY
  311. r.DiffSpotQty = r.TOTALSPOTQTY - r.OriTotalSpotQty
  312. r.DiffFutuQty = (r.BUYFUTUREQTY - r.ORIBUYFUTUREQTY) - (r.SELLFUTUREQTY - r.ORISELLFUTUREQTY)
  313. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODSUNITID)
  314. }
  315. func (r *ErmcpReportDayExposure) buildSql() string {
  316. var sqlId utils.SQLVal = "SELECT t.RECKONDATE," +
  317. " t.MIDDLEGOODSID," +
  318. " t.AREAUSERID," +
  319. " t.ORIBUYPLANQTY," +
  320. " t.ORIBUYPRICEDQTY," +
  321. " t.ORISELLPLANQTY," +
  322. " t.ORISELLPRICEDQTY," +
  323. " t.ORIBUYFUTUREQTY," +
  324. " t.ORISELLFUTUREQTY," +
  325. " t.BUYPLANQTY," +
  326. " t.BUYPRICEDQTY," +
  327. " t.SELLPLANQTY," +
  328. " t.SELLPRICEDQTY," +
  329. " t.BUYFUTUREQTY," +
  330. " t.SELLFUTUREQTY," +
  331. " t.TOTALSPOTQTY," +
  332. " t.TOTALFUTUREQTY," +
  333. " t.TOTALEXPOSURE," +
  334. " t.TOTALHEDGERATIO," +
  335. " t.TOTALNEEDHEDGEQTY," +
  336. " t.NEEDHEDGEEXPOSOURE," +
  337. " t.NEEDHEDGERATIO," +
  338. " g.middlegoodsname," +
  339. " g.middlegoodscode," +
  340. " g.needhedgeratio MIDDLEGOODSHEDGERATIO," +
  341. " g.goodsunitid" +
  342. " FROM RECKON_ERMCP_AREAEXPOSURE t" +
  343. " left join ERMS_MIDDLEGOODS g" +
  344. " on t.middlegoodsid = g.middlegoodsid" +
  345. " WHERE 1 = 1"
  346. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  347. sqlId.And("t.RECKONDATE", r.RECKONDATE)
  348. return sqlId.String()
  349. }
  350. // GetDataEx 获取敞口日报表
  351. func (r *ErmcpReportDayExposure) GetDataEx() (interface{}, error) {
  352. sData := make([]ErmcpReportDayExposure, 0)
  353. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  354. for i := range sData {
  355. sData[i].Calc()
  356. }
  357. return sData, err
  358. }
  359. // ErmcpReportDaySpot 现货日报表
  360. type ErmcpReportDaySpot struct {
  361. BUYPRICEDQTY float64 `json:"-" xorm:"'BUYPRICEDQTY'"` // 期末采购定价量
  362. SELLPRICEDQTY float64 `json:"-" xorm:"'SELLPRICEDQTY'"` // 期末销售定价量
  363. ORIBUYPRICEDQTY float64 `json:"-" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购定价量
  364. ORISELLPRICEDQTY float64 `json:"-" xorm:"'ORISELLPRICEDQTY'"` // 期初销售定价量
  365. TODAYBUYRECKONQTY float64 `json:"todaybuyreckonqty" xorm:"'TODAYBUYRECKONQTY'"` // 采购确定量
  366. TODAYSELLRECKONQTY float64 `json:"todaysellreckonqty" xorm:"'TODAYSELLRECKONQTY'"` // 销售确定量
  367. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 日照时期(yyyyMMdd)
  368. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
  369. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构T
  370. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
  371. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
  372. UNITID int32 `json:"-" xorm:"'UNITID'"` // 现货商品单位id
  373. BUYINQTY float64 `json:"buyinqty" xorm:"'BUYINQTY'"` // 采购入库量
  374. SELLOUTQTY float64 `json:"selloutqty" xorm:"'SELLOUTQTY'"` // 销售出库量
  375. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  376. TOTALBUYPRICEDQTY float64 `json:"totalbuypricedqty"` // 采购定价量 = 期末 - 期初
  377. TOTALSELLPRICEDQTY float64 `json:"totalsellpricedqty"` // 销售定价量 = 期末 - 期初
  378. BeginDate string `json:"-"` // 开始日期
  379. EndDate string `json:"-"` // 结束日期
  380. }
  381. // Calc 数据处理
  382. func (r *ErmcpReportDaySpot) Calc() {
  383. r.TOTALBUYPRICEDQTY = r.BUYPRICEDQTY - r.ORIBUYPRICEDQTY
  384. r.TOTALSELLPRICEDQTY = r.SELLPRICEDQTY - r.ORISELLPRICEDQTY
  385. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  386. }
  387. func (r *ErmcpReportDaySpot) buildSql() string {
  388. var sqlId utils.SQLVal = "select t.reckondate," +
  389. " t.BUYPRICEDQTY," +
  390. " t.SELLPRICEDQTY," +
  391. " t.Oribuypricedqty," +
  392. " t.Orisellpricedqty," +
  393. " t.TODAYBUYRECKONQTY," +
  394. " t.TODAYSELLRECKONQTY," +
  395. " t.RECKONDATE," +
  396. " t.WRSTANDARDID," +
  397. " t.AREAUSERID," +
  398. " w.wrstandardname," +
  399. " w.wrstandardcode," +
  400. " w.unitid," +
  401. " s.todaybuyinqty buyinqty," +
  402. " s.todayselloutqty selloutqty" +
  403. " from RECKON_ERMCP_AREASPOT t" +
  404. " left join Reckon_ERMCP_AreaStock s" +
  405. " on t.reckondate = s.reckondate" +
  406. " left join wrstandard w" +
  407. " on t.wrstandardid = w.wrstandardid" +
  408. " where 1 = 1"
  409. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  410. if r.WRSTANDARDID > 0 {
  411. sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
  412. }
  413. if r.RECKONDATE != "" {
  414. sqlId.And("t.RECKONDATE", r.RECKONDATE)
  415. } else if r.BeginDate != "" && r.BeginDate == r.EndDate {
  416. sqlId.And("t.RECKONDATE", r.BeginDate)
  417. } else {
  418. if r.BeginDate != "" {
  419. sqlId.BiggerOrEq("t.RECKONDATE", r.BeginDate)
  420. }
  421. if r.EndDate != "" {
  422. sqlId.LessOrEq("t.RECKONDATE", r.EndDate)
  423. }
  424. }
  425. sqlId.Join(" order by t.RECKONDATE")
  426. return sqlId.String()
  427. }
  428. // GetDataEx 获取现货日报表
  429. func (r *ErmcpReportDaySpot) GetDataEx() (interface{}, error) {
  430. sData := make([]ErmcpReportDaySpot, 0)
  431. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  432. for i := range sData {
  433. sData[i].Calc()
  434. }
  435. return sData, err
  436. }
  437. // ErmcpReportMonSpot 现货月报表
  438. type ErmcpReportMonSpot struct {
  439. CYCLETYPE int32 `json:"cycletype" xorm:"'cycletype'"` // 周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】
  440. CYCLETIME string `json:"cycletime" xorm:"'cycletime'"` // 周期时间 月(YYYYMM) 季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)【原值】
  441. BUYPRICEDQTY float64 `json:"-" xorm:"'BUYPRICEDQTY'"` // 期末采购定价量
  442. SELLPRICEDQTY float64 `json:"-" xorm:"'SELLPRICEDQTY'"` // 期末销售定价量
  443. ORIBUYPRICEDQTY float64 `json:"-" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购定价量
  444. ORISELLPRICEDQTY float64 `json:"-" xorm:"'ORISELLPRICEDQTY'"` // 期初销售定价量
  445. TODAYBUYRECKONQTY float64 `json:"todaybuyreckonqty" xorm:"'TODAYBUYRECKONQTY'"` // 采购确定量
  446. TODAYSELLRECKONQTY float64 `json:"todaysellreckonqty" xorm:"'TODAYSELLRECKONQTY'"` // 销售确定量
  447. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
  448. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构T
  449. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
  450. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
  451. UNITID int32 `json:"-" xorm:"'UNITID'"` // 现货商品单位id
  452. BUYINQTY float64 `json:"buyinqty" xorm:"'BUYINQTY'"` // 采购入库量
  453. SELLOUTQTY float64 `json:"selloutqty" xorm:"'SELLOUTQTY'"` // 销售出库量
  454. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  455. TOTALBUYPRICEDQTY float64 `json:"totalbuypricedqty"` // 采购定价量 = 期末 - 期初
  456. TOTALSELLPRICEDQTY float64 `json:"totalsellpricedqty"` // 销售定价量 = 期末 - 期初
  457. }
  458. // Calc 数据处理
  459. func (r *ErmcpReportMonSpot) Calc() {
  460. r.TOTALBUYPRICEDQTY = r.BUYPRICEDQTY - r.ORIBUYPRICEDQTY
  461. r.TOTALSELLPRICEDQTY = r.SELLPRICEDQTY - r.ORISELLPRICEDQTY
  462. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  463. }
  464. func (r *ErmcpReportMonSpot) buildSql() string {
  465. var sqlId utils.SQLVal = "select t.BUYPRICEDQTY," +
  466. " t.SELLPRICEDQTY," +
  467. " t.Oribuypricedqty," +
  468. " t.Orisellpricedqty," +
  469. " t.TODAYBUYRECKONQTY," +
  470. " t.TODAYSELLRECKONQTY," +
  471. " t.cycletype," +
  472. " t.cycletime," +
  473. " t.WRSTANDARDID," +
  474. " t.AREAUSERID," +
  475. " w.wrstandardname," +
  476. " w.wrstandardcode," +
  477. " w.unitid," +
  478. " s.todaybuyinqty buyinqty," +
  479. " s.todayselloutqty selloutqty" +
  480. " from Report_ERMCP_AreaSpot t" +
  481. " left join Report_ERMCP_AreaStock s" +
  482. " on t.cycletime = s.cycletime" +
  483. " and t.cycletype = s.cycletype" +
  484. " left join wrstandard w" +
  485. " on t.wrstandardid = w.wrstandardid" +
  486. " where t.cycletype = 1"
  487. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  488. sqlId.And("t.cycletime", r.CYCLETIME)
  489. return sqlId.String()
  490. }
  491. // GetDataEx 获取现货月报表
  492. func (r *ErmcpReportMonSpot) GetDataEx() (interface{}, error) {
  493. sData := make([]ErmcpReportMonSpot, 0)
  494. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  495. for i := range sData {
  496. sData[i].Calc()
  497. }
  498. return sData, err
  499. }