ermcpReport.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. // 财务日报表
  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. // 数据处理
  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. // 获取日报表
  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. // 财务日报表/款项
  69. type ErmcpReportDayFRKx struct {
  70. USERID int64 `json:"userid" xorm:"'USERID'"` // 机构ID
  71. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  72. }
  73. // 获取日报表款项记录
  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. // 报表合同操作记录通用查询
  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. // 处理数据
  102. func (r *ErmcpReportOPLog) Calc() {
  103. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  104. r.APPLYNAME = mtpcache.GetUserNameByUserId(r.APPLYID)
  105. // 数据库注释与返回值映身关系: 结算量->确定量, 收款->收款金额, 退款->退款金额, 付款->付款金额, 收票->收票金额, 开票->开票金额
  106. sDes := []string{"点价价格", "点价数量", "确定量", "其它费用", "追加保证金", "溢短金额", "调整金额", "付款", "收款", "退款",
  107. "收票", "开票", "提交审核(合同)", "审核通过(合同)", "审核拒绝(合同)", "合同撤回", "提交审核(计划)",
  108. "审核通过(计划)", "审核拒绝(计划)", "计划撤回", "正常完结(合同)", "异常终止(合同)", "退还保证金"}
  109. if r.OPERATELOGTYPE >= 1 && r.OPERATELOGTYPE <= 23 {
  110. r.OPTYPENAME = sDes[r.OPERATELOGTYPE-1]
  111. }
  112. if r.CONTRACTTYPE == 1 {
  113. r.LOGTYPENAME = "采购"
  114. } else if r.CONTRACTTYPE == -1 {
  115. r.LOGTYPENAME = "销售"
  116. }
  117. if r.BIZTYPE == 1 {
  118. r.LOGTYPENAME += "计划"
  119. } else if r.BIZTYPE == 2 {
  120. r.LOGTYPENAME += "合同"
  121. }
  122. }
  123. func (r *ErmcpReportOPLog) buildSql() string {
  124. var sqlId utils.SQLVal = "with tmp as" +
  125. " (select to_char(t.hedgeplanid) relatedid," +
  126. " t.hedgeplanno relatedno," +
  127. " 1 as logType," +
  128. " t.contracttype" +
  129. " from ermcp_hedgeplan t" +
  130. " where t.areauserid = %v" +
  131. " union all" +
  132. " select to_char(t.spotcontractid)," +
  133. " t.contractno," +
  134. " 2 as logType," +
  135. " t.contracttype" +
  136. " from ermcp_spotcontract t" +
  137. " where t.userid = %v)" +
  138. " SELECT to_char(t.LOGID) LOGID," +
  139. " t.BIZTYPE," +
  140. " t.OPERATELOGTYPE," +
  141. " to_char(t.RELATEDID) RELATEDID," +
  142. " t.LOGVALUE," +
  143. " to_char(t.LOGDATETIME, 'yyyy-mm-dd hh24:mi:ss') LOGDATETIME," +
  144. " t.TRADEDATE," +
  145. " t.APPLYID," +
  146. " t.CONTRACTTYPE," +
  147. " t.USERID," +
  148. " t.WRSTANDARDID," +
  149. " tmp.relatedno," +
  150. " w.wrstandardname," +
  151. " w.wrstandardcode," +
  152. " w.unitid" +
  153. " FROM ERMCP_CONTRACTOPERATELOG t" +
  154. " inner join tmp" +
  155. " on t.RELATEDID = tmp.RELATEDID" +
  156. " and t.userid = %v" +
  157. " left join wrstandard w on t.wrstandardid=w.wrstandardid" +
  158. " WHERE 1 = 1"
  159. sqlId = utils.SQLVal(fmt.Sprintf(sqlId.String(), r.USERID, r.USERID, r.USERID))
  160. // 筛选条件
  161. sqlId.And("t.TRADEDATE", r.TRADEDATE)
  162. if r.WRSTANDARDID > 0 {
  163. sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
  164. }
  165. if r.LogTypeFilter != "" {
  166. sqlId.Join(fmt.Sprintf(" and t.OPERATELOGTYPE in(%v)", r.LogTypeFilter))
  167. }
  168. return sqlId.String()
  169. }
  170. // 获取日志记录
  171. func (r *ErmcpReportOPLog) GetDataEx() (interface{}, error) {
  172. sData := make([]ErmcpReportOPLog, 0)
  173. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  174. for i := range sData {
  175. sData[i].Calc()
  176. }
  177. return sData, err
  178. }
  179. // 财务月报表
  180. type ErmcpReportMonthFR struct {
  181. CYCLETYPE int32 `json:"cycletype" xorm:"'cycletype'"` // 周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】
  182. CYCLETIME string `json:"cycletime" xorm:"'cycletime'"` // 周期时间 月(YYYYMM) 季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)【原值】
  183. AREAUSERID int64 `json:"areauserid" xorm:"'areauserid'"` // 所属机构【原值】
  184. COLLECTMONEYCOUNT int32 `json:"collectmoneycount" xorm:"'collectmoneycount'"` // 今日收款笔数 【汇总】
  185. COLLECTMONEYAMOUNT float64 `json:"collectmoneyamount" xorm:"'collectmoneyamount'"` // 今日收款金额【汇总】
  186. PAYMONEYCOUNT int32 `json:"paymoneycount" xorm:"'paymoneycount'"` // 今日付款笔数【汇总】
  187. PAYMONEYAMOUNT float64 `json:"paymoneyamount" xorm:"'paymoneyamount'"` // 今日付款金额【汇总】
  188. COLLECTINVOICECOUNT int32 `json:"collectinvoicecount" xorm:"'collectinvoicecount'"` // 今日开票笔数【汇总】
  189. COLLECTINVOICEAMOUNT float64 `json:"collectinvoiceamount" xorm:"'collectinvoiceamount'"` // 今日开票金额【汇总】
  190. PAYINVOICECOUNT int32 `json:"payinvoicecount" xorm:"'payinvoicecount'"` // 今日收票笔数【汇总】
  191. PAYINVOICEAMOUNT float64 `json:"payinvoiceamount" xorm:"'payinvoiceamount'"` // 今日收票金额【汇总】
  192. UPDATETIME string `json:"updatetime" xorm:"'updatetime'"` // 更新时间
  193. DayFR []ErmcpReportDayFR `json:"dayFr"` // 日报表明细
  194. }
  195. // 数据处理
  196. func (r *ErmcpReportMonthFR) Calc() {
  197. }
  198. func (r *ErmcpReportMonthFR) buildSql() string {
  199. var sqlId utils.SQLVal = "SELECT t.CYCLETYPE," +
  200. " t.CYCLETIME," +
  201. " t.AREAUSERID," +
  202. " t.COLLECTMONEYCOUNT," +
  203. " t.COLLECTMONEYAMOUNT," +
  204. " t.PAYMONEYCOUNT," +
  205. " t.PAYMONEYAMOUNT," +
  206. " t.COLLECTINVOICECOUNT," +
  207. " t.COLLECTINVOICEAMOUNT," +
  208. " t.PAYINVOICECOUNT," +
  209. " t.PAYINVOICEAMOUNT," +
  210. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh:mi:ss') UPDATETIME" +
  211. " FROM REPORT_ERMCP_AREAFR t" +
  212. " WHERE 1 = 1"
  213. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  214. sqlId.And("t.CYCLETYPE", 1)
  215. sqlId.And("t.CYCLETIME", r.CYCLETIME)
  216. return sqlId.String()
  217. }
  218. // 获取月报表
  219. func (r *ErmcpReportMonthFR) GetDataEx() (interface{}, error) {
  220. sData := make([]ErmcpReportMonthFR, 0)
  221. // 月报表
  222. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  223. // 日报表明细
  224. if len(r.CYCLETIME) != 6 {
  225. // 月报表的日期应是6位,如 202101
  226. return nil, nil
  227. }
  228. t1 := r.CYCLETIME + "01"
  229. t2 := r.CYCLETIME + "31"
  230. for i := range sData {
  231. sData[i].Calc()
  232. dayM := ErmcpReportDayFR{AREAUSERID: r.AREAUSERID, BeginDate: t1, EndDate: t2}
  233. if dObj, err := dayM.GetDataEx(); err == nil {
  234. if d, ok := dObj.([]ErmcpReportDayFR); ok {
  235. sData[i].DayFR = d
  236. }
  237. }
  238. }
  239. return sData, err
  240. }
  241. // 敞口日报表
  242. type ErmcpReportDayExposure struct {
  243. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 日照时期(yyyyMMdd)
  244. MIDDLEGOODSID int64 `json:"middlegoodsid" xorm:"'MIDDLEGOODSID'"` // 套保品种ID
  245. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  246. ORIBUYPLANQTY float64 `json:"oribuyplanqty" xorm:"'ORIBUYPLANQTY'"` // 期初采购计划数量
  247. ORIBUYPRICEDQTY float64 `json:"oribuypricedqty" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购合同已定价数量
  248. ORISELLPLANQTY float64 `json:"orisellplanqty" xorm:"'ORISELLPLANQTY'"` // 期初销售计划数量
  249. ORISELLPRICEDQTY float64 `json:"orisellpricedqty" xorm:"'ORISELLPRICEDQTY'"` // 期初销售合同已定价数量
  250. ORIBUYFUTUREQTY float64 `json:"oribuyfutureqty" xorm:"'ORIBUYFUTUREQTY'"` // 期初买入期货数量
  251. ORISELLFUTUREQTY float64 `json:"orisellfutureqty" xorm:"'ORISELLFUTUREQTY'"` // 期初卖出期货数量
  252. BUYPLANQTY float64 `json:"buyplanqty" xorm:"'BUYPLANQTY'"` // 采购计划数量
  253. BUYPRICEDQTY float64 `json:"buypricedqty" xorm:"'BUYPRICEDQTY'"` // 采购合同已定价数量
  254. SELLPLANQTY float64 `json:"sellplanqty" xorm:"'SELLPLANQTY'"` // 销售计划数量
  255. SELLPRICEDQTY float64 `json:"sellpricedqty" xorm:"'SELLPRICEDQTY'"` // 销售合同已定价数量
  256. BUYFUTUREQTY float64 `json:"buyfutureqty" xorm:"'BUYFUTUREQTY'"` // 买入期货数量
  257. SELLFUTUREQTY float64 `json:"sellfutureqty" xorm:"'SELLFUTUREQTY'"` // 卖出期货数量
  258. TOTALSPOTQTY float64 `json:"totalspotqty" xorm:"'TOTALSPOTQTY'"` // 现货数量
  259. TOTALFUTUREQTY float64 `json:"totalfutureqty" xorm:"'TOTALFUTUREQTY'"` // 期货数量
  260. TOTALEXPOSURE float64 `json:"totalexposure" xorm:"'TOTALEXPOSURE'"` // 总敞口
  261. TOTALHEDGERATIO float64 `json:"totalhedgeratio" xorm:"'TOTALHEDGERATIO'"` // 敞口比例
  262. TOTALNEEDHEDGEQTY float64 `json:"totalneedhedgeqty" xorm:"'TOTALNEEDHEDGEQTY'"` // 期货应套保量
  263. NEEDHEDGEEXPOSOURE float64 `json:"needhedgeexposoure" xorm:"'NEEDHEDGEEXPOSOURE'"` // 应套保敞口
  264. NEEDHEDGERATIO float64 `json:"needhedgeratio" xorm:"'NEEDHEDGERATIO'"` // 应套保敞口比例
  265. MIDDLEGOODSNAME string `json:"middlegoodsname" xorm:"'MIDDLEGOODSNAME'"` // 套保品种名称
  266. MIDDLEGOODSCODE string `json:"middlegoodscode" xorm:"'MIDDLEGOODSCODE'"` // 套保品种代码
  267. MIDDLEGOODSHEDGERATIO float64 `json:"middlegoodshedgeratio" xorm:"'MIDDLEGOODSHEDGERATIO'"` // 应套保比例
  268. GOODSUNITID int32 `json:"-" xorm:"'GOODSUNITID'"` // 套保商品单位id
  269. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  270. OriTotalSpotQty float64 `json:"oriTotalSpotQty"` // 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
  271. OriTotalFutuQty float64 `json:"oriTotalFutuQty"` // 期初期货数量=期初买入期货数量-期初卖出期货数量
  272. DiffSpotQty float64 `json:"diffSpotQty"` // 今日变动量(现货) = 现货数量 - 期初现货数量
  273. DiffFutuQty float64 `json:"diffFutuQty"` // 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
  274. }
  275. // 数据处理
  276. func (r *ErmcpReportDayExposure) Calc() {
  277. r.OriTotalSpotQty = (r.ORISELLPLANQTY - r.ORISELLPRICEDQTY) - (r.ORIBUYPLANQTY - r.ORIBUYPRICEDQTY)
  278. r.OriTotalFutuQty = r.ORIBUYFUTUREQTY - r.ORISELLFUTUREQTY
  279. r.DiffSpotQty = r.TOTALSPOTQTY - r.OriTotalSpotQty
  280. r.DiffFutuQty = (r.BUYFUTUREQTY - r.ORIBUYFUTUREQTY) - (r.SELLFUTUREQTY - r.ORISELLFUTUREQTY)
  281. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODSUNITID)
  282. }
  283. func (r *ErmcpReportDayExposure) buildSql() string {
  284. var sqlId utils.SQLVal = "SELECT t.RECKONDATE," +
  285. " t.MIDDLEGOODSID," +
  286. " t.AREAUSERID," +
  287. " t.ORIBUYPLANQTY," +
  288. " t.ORIBUYPRICEDQTY," +
  289. " t.ORISELLPLANQTY," +
  290. " t.ORISELLPRICEDQTY," +
  291. " t.ORIBUYFUTUREQTY," +
  292. " t.ORISELLFUTUREQTY," +
  293. " t.BUYPLANQTY," +
  294. " t.BUYPRICEDQTY," +
  295. " t.SELLPLANQTY," +
  296. " t.SELLPRICEDQTY," +
  297. " t.BUYFUTUREQTY," +
  298. " t.SELLFUTUREQTY," +
  299. " t.TOTALSPOTQTY," +
  300. " t.TOTALFUTUREQTY," +
  301. " t.TOTALEXPOSURE," +
  302. " t.TOTALHEDGERATIO," +
  303. " t.TOTALNEEDHEDGEQTY," +
  304. " t.NEEDHEDGEEXPOSOURE," +
  305. " t.NEEDHEDGERATIO," +
  306. " g.middlegoodsname," +
  307. " g.middlegoodscode," +
  308. " g.needhedgeratio MIDDLEGOODSHEDGERATIO," +
  309. " g.goodsunitid" +
  310. " FROM RECKON_ERMCP_AREAEXPOSURE t" +
  311. " left join ERMS_MIDDLEGOODS g" +
  312. " on t.middlegoodsid = g.middlegoodsid" +
  313. " WHERE 1 = 1"
  314. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  315. sqlId.And("t.RECKONDATE", r.RECKONDATE)
  316. return sqlId.String()
  317. }
  318. // 获取敞口日报表
  319. func (r *ErmcpReportDayExposure) GetDataEx() (interface{}, error) {
  320. sData := make([]ErmcpReportDayExposure, 0)
  321. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  322. for i := range sData {
  323. sData[i].Calc()
  324. }
  325. return sData, err
  326. }
  327. // 现货日报表
  328. type ErmcpReportDaySpot struct {
  329. BUYPRICEDQTY float64 `json:"-" xorm:"'BUYPRICEDQTY'"` // 期末采购定价量
  330. SELLPRICEDQTY float64 `json:"-" xorm:"'SELLPRICEDQTY'"` // 期末销售定价量
  331. ORIBUYPRICEDQTY float64 `json:"-" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购定价量
  332. ORISELLPRICEDQTY float64 `json:"-" xorm:"'ORISELLPRICEDQTY'"` // 期初销售定价量
  333. TODAYBUYRECKONQTY float64 `json:"todaybuyreckonqty" xorm:"'TODAYBUYRECKONQTY'"` // 采购确定量
  334. TODAYSELLRECKONQTY float64 `json:"todaysellreckonqty" xorm:"'TODAYSELLRECKONQTY'"` // 销售确定量
  335. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 日照时期(yyyyMMdd)
  336. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
  337. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构T
  338. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
  339. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
  340. UNITID int32 `json:"-" xorm:"'UNITID'"` // 现货商品单位id
  341. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  342. TOTALBUYPRICEDQTY float64 `json:"totalbuypricedqty"` // 采购定价量 = 期末 - 期初
  343. TOTALSELLPRICEDQTY float64 `json:"totalsellpricedqty"` // 销售定价量 = 期末 - 期初
  344. BeginDate string `json:"-"` // 开始日期
  345. EndDate string `json:"-"` // 结束日期
  346. }
  347. // 数据处理
  348. func (r *ErmcpReportDaySpot) Calc() {
  349. r.TOTALBUYPRICEDQTY = r.BUYPRICEDQTY - r.ORIBUYPRICEDQTY
  350. r.TOTALSELLPRICEDQTY = r.SELLPRICEDQTY - r.ORISELLPRICEDQTY
  351. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  352. }
  353. func (r *ErmcpReportDaySpot) buildSql() string {
  354. var sqlId utils.SQLVal = "select t.BUYPRICEDQTY," +
  355. " t.SELLPRICEDQTY," +
  356. " t.Oribuypricedqty," +
  357. " t.Orisellpricedqty," +
  358. " t.TODAYBUYRECKONQTY," +
  359. " t.TODAYSELLRECKONQTY," +
  360. " t.RECKONDATE," +
  361. " t.WRSTANDARDID," +
  362. " t.AREAUSERID," +
  363. " w.wrstandardname," +
  364. " w.wrstandardcode," +
  365. " w.unitid" +
  366. " from RECKON_ERMCP_AREASPOT t" +
  367. " left join wrstandard w" +
  368. " on t.wrstandardid = w.wrstandardid" +
  369. " where 1 = 1"
  370. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  371. if r.WRSTANDARDID > 0 {
  372. sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
  373. }
  374. if r.RECKONDATE != "" {
  375. sqlId.And("t.RECKONDATE", r.RECKONDATE)
  376. } else if r.BeginDate != "" && r.BeginDate == r.EndDate {
  377. sqlId.And("t.RECKONDATE", r.BeginDate)
  378. } else {
  379. if r.BeginDate != "" {
  380. sqlId.BiggerOrEq("t.RECKONDATE", r.BeginDate)
  381. }
  382. if r.EndDate != "" {
  383. sqlId.LessOrEq("t.RECKONDATE", r.EndDate)
  384. }
  385. }
  386. sqlId.Join(" order by t.RECKONDATE")
  387. return sqlId.String()
  388. }
  389. // 获取现货日报表
  390. func (r *ErmcpReportDaySpot) GetDataEx() (interface{}, error) {
  391. sData := make([]ErmcpReportDaySpot, 0)
  392. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  393. for i := range sData {
  394. sData[i].Calc()
  395. }
  396. return sData, err
  397. }
  398. // 现货月报表
  399. type ErmcpReportMonSpot struct {
  400. CYCLETYPE int32 `json:"cycletype" xorm:"'cycletype'"` // 周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】
  401. CYCLETIME string `json:"cycletime" xorm:"'cycletime'"` // 周期时间 月(YYYYMM) 季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)【原值】
  402. BUYPRICEDQTY float64 `json:"-" xorm:"'BUYPRICEDQTY'"` // 期末采购定价量
  403. SELLPRICEDQTY float64 `json:"-" xorm:"'SELLPRICEDQTY'"` // 期末销售定价量
  404. ORIBUYPRICEDQTY float64 `json:"-" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购定价量
  405. ORISELLPRICEDQTY float64 `json:"-" xorm:"'ORISELLPRICEDQTY'"` // 期初销售定价量
  406. TODAYBUYRECKONQTY float64 `json:"todaybuyreckonqty" xorm:"'TODAYBUYRECKONQTY'"` // 采购确定量
  407. TODAYSELLRECKONQTY float64 `json:"todaysellreckonqty" xorm:"'TODAYSELLRECKONQTY'"` // 销售确定量
  408. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
  409. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构T
  410. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
  411. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
  412. UNITID int32 `json:"-" xorm:"'UNITID'"` // 现货商品单位id
  413. ENUMDICNAME string `json:"enumdicname"` // 现货商品单位名称
  414. TOTALBUYPRICEDQTY float64 `json:"totalbuypricedqty"` // 采购定价量 = 期末 - 期初
  415. TOTALSELLPRICEDQTY float64 `json:"totalsellpricedqty"` // 销售定价量 = 期末 - 期初
  416. }
  417. // 数据处理
  418. func (r *ErmcpReportMonSpot) Calc() {
  419. r.TOTALBUYPRICEDQTY = r.BUYPRICEDQTY - r.ORIBUYPRICEDQTY
  420. r.TOTALSELLPRICEDQTY = r.SELLPRICEDQTY - r.ORISELLPRICEDQTY
  421. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  422. }
  423. func (r *ErmcpReportMonSpot) buildSql() string {
  424. var sqlId utils.SQLVal = "select t.BUYPRICEDQTY," +
  425. " t.SELLPRICEDQTY," +
  426. " t.Oribuypricedqty," +
  427. " t.Orisellpricedqty," +
  428. " t.TODAYBUYRECKONQTY," +
  429. " t.TODAYSELLRECKONQTY," +
  430. " t.cycletype," +
  431. " t.cycletime," +
  432. " t.WRSTANDARDID," +
  433. " t.AREAUSERID," +
  434. " w.wrstandardname," +
  435. " w.wrstandardcode," +
  436. " w.unitid" +
  437. " from Report_ERMCP_AreaSpot t" +
  438. " left join wrstandard w" +
  439. " on t.wrstandardid = w.wrstandardid" +
  440. " where t.cycletype = 1"
  441. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  442. sqlId.And("t.cycletime", r.CYCLETIME)
  443. return sqlId.String()
  444. }
  445. // 获取现货月报表
  446. func (r *ErmcpReportMonSpot) GetDataEx() (interface{}, error) {
  447. sData := make([]ErmcpReportMonSpot, 0)
  448. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  449. for i := range sData {
  450. sData[i].Calc()
  451. }
  452. return sData, err
  453. }