ermcpHedgePlan.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/1/7 17:58
  4. * @Modify : 2021/1/7 17:58
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/logger"
  11. "mtp2_if/mtpcache"
  12. )
  13. // ErmcpHedgePlan 套保计划表结构
  14. type ErmcpHedgePlan struct {
  15. Areauserid int64 `json:"areauserid" xorm:"'Areauserid'"` // 用户ID
  16. Hedgeplanid string `json:"hedgeplanid" xorm:"'Hedgeplanid'"` // 套保计划ID(601+Unix秒时间戳(10位)+xxxxxx)
  17. Hedgeplanno string `json:"hedgeplanno" xorm:"'Hedgeplanno'"` // 套保计划编号(名称)
  18. Contracttype int `json:"contracttype" xorm:"'Contracttype'"` // 计划类型 - 1:采购 -1:销售
  19. Deliverygoodsid int `json:"deliverygoodsid" xorm:"'Deliverygoodsid'"` // 现货品种ID
  20. Deliverygoodsname string `json:"deliverygoodsname" xorm:"'Deliverygoodsname'"` // 现货品种名称
  21. Wrstandardid int `json:"wrstandardid" xorm:"'Wrstandardid'"` // 现货商品ID
  22. Wrstandardname string `json:"wrstandardname" xorm:"'Wrstandardname'"` // 现货商品名称
  23. Producttype int `json:"producttype" xorm:"'Producttype'"` // 产品类型 - 1:标准仓单 2:等标 3:非标
  24. Spotgoodsdesc string `json:"spotgoodsdesc" xorm:"'Spotgoodsdesc'"` // 商品型号
  25. Planqty float64 `json:"planqty" xorm:"'Planqty'"` // 计划数量
  26. Convertfactor float64 `json:"convertfactor" xorm:"'Convertfactor'"` // 标仓系数
  27. Plantime string `json:"plantime" xorm:"'Plantime'"` // 计划时间
  28. Hedgeplanstatus int `json:"hedgeplanstatus" xorm:"'Hedgeplanstatus'"` // 套保计划状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
  29. Remark string `json:"remark" xorm:"'Remark'"` // 备注
  30. CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  31. UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  32. AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
  33. UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位id
  34. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  35. }
  36. func (r *ErmcpHedgePlan) calc() {
  37. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  38. }
  39. func (r *ErmcpHedgePlan) buildSql(status string) string {
  40. str := "select to_char(t.Hedgeplanid) Hedgeplanid," +
  41. " t.Hedgeplanno," +
  42. " t.Contracttype," +
  43. " t.Deliverygoodsid," +
  44. " t.g.Deliverygoodsname," +
  45. " t.Wrstandardid," +
  46. " w.Wrstandardname," +
  47. " w.unitid," +
  48. " t.Producttype," +
  49. " t.Spotgoodsdesc," +
  50. " t.Planqty," +
  51. " t.Convertfactor," +
  52. " to_char(t.Plantime,'yyyy-mm-dd hh24:mi:ss') Plantime," +
  53. " to_char(t.createtime,'yyyy-mm-dd hh24:mi:ss') createtime," +
  54. " to_char(t.updatetime, 'yyyy-mm-dd hh24:mi:ss') updatetime," +
  55. " to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
  56. " t.Hedgeplanstatus," +
  57. " t.Remark" +
  58. " from ermcp_hedgeplan t" +
  59. " left join wrstandard w" +
  60. " on t.wrstandardid = w.wrstandardid" +
  61. " left join deliverygoods g" +
  62. " on t.deliverygoodsid = g.deliverygoodsid" +
  63. " where t.hedgeplanstatus in (%v) and t.areauserid=%v"
  64. if status == "2" {
  65. // 执行中状态,按审核时间倒序
  66. str += " order by t.audittime desc"
  67. } else {
  68. str += " order by t.updatetime desc"
  69. }
  70. return fmt.Sprintf(str, status, r.Areauserid)
  71. }
  72. // GetData 从数据库中查询套保计划数据
  73. func (r *ErmcpHedgePlan) GetData(status string) ([]ErmcpHedgePlan, error) {
  74. e := db.GetEngine()
  75. sData := make([]ErmcpHedgePlan, 0)
  76. if err := e.SQL(r.buildSql(status)).Find(&sData); err != nil {
  77. logger.GetLogger().Errorf("query hedgeplan:%v", err)
  78. return sData, err
  79. }
  80. for i := range sData {
  81. sData[i].calc()
  82. }
  83. return sData, nil
  84. }