ermcpReport.go 23 KB

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