ermcpOPApply.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/1/12 10:38
  4. * @Modify : 2021/1/12 10:38
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/logger"
  11. "mtp2_if/mtpcache"
  12. "strconv"
  13. )
  14. // ErmcpOPApplyModel 现货合同操作数据
  15. type ErmcpOPApplyModel struct {
  16. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  17. OPERATEAPPLYID string `json:"operateapplyid" xorm:"'OPERATEAPPLYID'"` // 操作申请ID(603+Unix秒时间戳(10位)+xxxxxx)
  18. OPERATEAPPLYTYPE int32 `json:"operateapplytype" xorm:"'OPERATEAPPLYTYPE'"` // 操作申请类型 - 1:点价 2:结算登记 3:款项登记 4:发票登记
  19. RELATEDID string `json:"relatedid" xorm:"'RELATEDID'"` // 现货合同ID
  20. DETAILJSON string `json:"-" xorm:"'DETAILJSON'"` // 明细JSON
  21. APPLYID string `json:"applyid" xorm:"'APPLYID'"` // 申请人
  22. APPLYTIME string `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间
  23. APPLYSTATUS int32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回
  24. AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
  25. CONTRACTTYPE int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购 -1:销售
  26. CONTRACTNO string `json:"contractno" xorm:"'CONTRACTNO'"` // 合同编号
  27. PRICETYPE int32 `json:"pricetype" xorm:"'PRICETYPE'"` // 定价类型 - 1:一口价 2:点价 3:暂定价
  28. PRICEMOVE float64 `json:"pricemove" xorm:"'PRICEMOVE'"` // 升贴水
  29. GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  30. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 点价合约
  31. EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
  32. BUYUSERNAME string `json:"buyusername" xorm:"'BUYUSERNAME'"` // 采购方名称
  33. SELLUSERNAME string `json:"sellusername" xorm:"'SELLUSERNAME'"` // 销售方名字
  34. AUDITID string `json:"auditid" xorm:"'AUDITID'"` // 审核人ID
  35. APPLYNAME string `json:"applyname" xorm:"'APPLYNAME'"` // 申请人名称
  36. AUDITNAME string `json:"auditname" xorm:"'AUDITNAME'"` // 审核人名称
  37. CONTRACTSTATUS int32 `json:"contractstatus" xorm:"'CONTRACTSTATUS'"` // 合同状态- 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
  38. ATTACHURL string `json:"attachurl" xorm:"'ATTACHURL'"` // 附件
  39. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
  40. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
  41. WRSTANDARDID int `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品id
  42. }
  43. func (r *ErmcpOPApplyModel) calc() {
  44. // 管理端applyid存的是管理员表的autoid
  45. if len(r.APPLYID) < 8 && r.APPLYNAME == "" {
  46. if id, err := strconv.ParseInt(r.APPLYID, 10, 64); err == nil {
  47. r.APPLYNAME = mtpcache.GetSystemmangerLoginCode(id)
  48. }
  49. }
  50. if len(r.AUDITID) < 8 && r.AUDITNAME == "" {
  51. if id, err := strconv.ParseInt(r.AUDITID, 10, 64); err == nil {
  52. r.AUDITNAME = mtpcache.GetSystemmangerLoginCode(id)
  53. }
  54. }
  55. }
  56. func (r *ErmcpOPApplyModel) buildSql(opType int32) string {
  57. sqlId := "select to_char(t.OPERATEAPPLYID) OPERATEAPPLYID," +
  58. " t.OPERATEAPPLYTYPE," +
  59. " to_char(t.RELATEDID) RELATEDID," +
  60. " t.DETAILJSON," +
  61. " to_char(t.APPLYID) APPLYID," +
  62. " to_char(t.APPLYTIME, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME," +
  63. " t.APPLYSTATUS," +
  64. " to_char(t.auditid) auditid," +
  65. " to_char(t.AUDITTIME, 'yyyy-mm-dd hh24:mi:ss') AUDITTIME," +
  66. " t.CONTRACTTYPE," +
  67. " to_char(t.attachurl) attachurl," +
  68. " s.CONTRACTNO," +
  69. " s.PRICETYPE," +
  70. " s.pricemove," +
  71. " s.userid," +
  72. " s.contractstatus," +
  73. " w.wrstandardname," +
  74. " w.wrstandardcode," +
  75. " w.wrstandardid," +
  76. " g.GOODSNAME," +
  77. " g.GOODSCODE," +
  78. " e.EnumdicName," +
  79. " u3.logincode APPLYName," +
  80. " u4.logincode auditName," +
  81. " u1.accountname buyuserName," +
  82. " u2.accountname selluserName" +
  83. " from ermcp_contractoperateapply t" +
  84. " left join ermcp_spotcontract s" +
  85. " on t.relatedid = s.spotcontractid" +
  86. " left join goods g" +
  87. " on s.goodsid = g.goodsid" +
  88. " left join wrstandard w" +
  89. " on s.wrstandardid = w.wrstandardid" +
  90. " left join loginaccount u3" +
  91. " on t.applyid = u3.loginid" +
  92. " left join loginaccount u4" +
  93. " on t.auditid = u4.loginid" +
  94. " left join useraccount u1" +
  95. " on s.buyuserid = u1.userid" +
  96. " left join useraccount u2" +
  97. " on s.selluserid = u2.userid" +
  98. " left join enumdicitem e" +
  99. " on e.enumitemname = w.unitid" +
  100. " and e.enumdiccode = 'goodsunit'" +
  101. " where t.operateapplytype = %v" +
  102. " and s.userid = %v"
  103. if len(r.RELATEDID) > 0 {
  104. sqlId = sqlId + " and t.relatedid=" + r.RELATEDID
  105. }
  106. if len(r.OPERATEAPPLYID) > 0 {
  107. sqlId += " and t.operateapplyid =" + r.OPERATEAPPLYID
  108. }
  109. return fmt.Sprintf(sqlId, opType, r.USERID)
  110. }
  111. // GetData 从数据库中查询合同操作申请相关信息, opType 操作申请类型 - 1:点价 2:结算登记 3:款项登记 4:发票登记
  112. func (r *ErmcpOPApplyModel) GetData(opType int32) ([]ErmcpOPApplyModel, error) {
  113. sData := make([]ErmcpOPApplyModel, 0)
  114. e := db.GetEngine()
  115. s := e.SQL(r.buildSql(opType))
  116. if err := s.Find(&sData); err != nil {
  117. logger.GetLogger().Errorf("ermcp query fail:%v", err)
  118. return sData, err
  119. }
  120. for i := range sData {
  121. sData[i].calc()
  122. }
  123. return sData, nil
  124. }