ermcpOPApply.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. DELIVERYGOODSID int `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货商品ID
  43. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  44. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  45. FilterAppStatus string `json:"-"` // 状态过滤条件
  46. UserType int32 `json:"-"`
  47. }
  48. func (r *ErmcpOPApplyModel) calc() {
  49. // 管理端applyid存的是管理员表的autoid
  50. if len(r.APPLYID) < 8 && r.APPLYNAME == "" {
  51. if id, err := strconv.ParseInt(r.APPLYID, 10, 64); err == nil {
  52. r.APPLYNAME = mtpcache.GetSystemmangerLoginCode(id)
  53. }
  54. }
  55. if len(r.AUDITID) < 8 && r.AUDITNAME == "" {
  56. if id, err := strconv.ParseInt(r.AUDITID, 10, 64); err == nil {
  57. r.AUDITNAME = mtpcache.GetSystemmangerLoginCode(id)
  58. }
  59. }
  60. }
  61. func (r *ErmcpOPApplyModel) buildSql(opType int32) string {
  62. sqlId := "select to_char(t.OPERATEAPPLYID) OPERATEAPPLYID," +
  63. " t.OPERATEAPPLYTYPE," +
  64. " to_char(t.RELATEDID) RELATEDID," +
  65. " t.DETAILJSON," +
  66. " to_char(t.APPLYID) APPLYID," +
  67. " to_char(t.APPLYTIME, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME," +
  68. " t.APPLYSTATUS," +
  69. " to_char(t.auditid) auditid," +
  70. " to_char(t.AUDITTIME, 'yyyy-mm-dd hh24:mi:ss') AUDITTIME," +
  71. " t.CONTRACTTYPE," +
  72. " to_char(t.attachurl) attachurl," +
  73. " s.CONTRACTNO," +
  74. " s.PRICETYPE," +
  75. " s.pricemove," +
  76. " s.userid," +
  77. " s.contractstatus," +
  78. " dg.deliverygoodsid," +
  79. " dg.deliverygoodscode," +
  80. " dg.deliverygoodsname," +
  81. " w.wrstandardname," +
  82. " w.wrstandardcode," +
  83. " w.wrstandardid," +
  84. " g.GOODSNAME," +
  85. " g.GOODSCODE," +
  86. " e.EnumdicName," +
  87. " u3.logincode APPLYName," +
  88. " u4.logincode auditName," +
  89. " u1.accountname buyuserName," +
  90. " u2.accountname selluserName" +
  91. " from ermcp_contractoperateapply t" +
  92. " left join ermcp_spotcontract s" +
  93. " on t.relatedid = s.spotcontractid" +
  94. " left join goods g" +
  95. " on s.goodsid = g.goodsid" +
  96. " left join wrstandard w" +
  97. " on s.wrstandardid = w.wrstandardid" +
  98. " left join loginaccount u3" +
  99. " on t.applyid = u3.loginid" +
  100. " left join loginaccount u4" +
  101. " on t.auditid = u4.loginid" +
  102. " left join useraccount u1" +
  103. " on s.buyuserid = u1.userid" +
  104. " left join useraccount u2" +
  105. " on s.selluserid = u2.userid" +
  106. " left join deliverygoods dg" +
  107. " on t.deliverygoodsid = dg.deliverygoodsid" +
  108. " left join enumdicitem e" +
  109. " on e.enumitemname = w.unitid" +
  110. " and e.enumdiccode = 'goodsunit'" +
  111. " where t.operateapplytype = %v"
  112. if len(r.RELATEDID) > 0 {
  113. sqlId = sqlId + " and t.relatedid=" + r.RELATEDID
  114. }
  115. if len(r.OPERATEAPPLYID) > 0 {
  116. sqlId += " and t.operateapplyid =" + r.OPERATEAPPLYID
  117. }
  118. if len(r.FilterAppStatus) > 0 {
  119. sqlId += fmt.Sprintf(" and t.applystatus in(%v)", r.FilterAppStatus)
  120. }
  121. // 终端没传用户类型过来
  122. if r.UserType == 0 {
  123. areaUserId := mtpcache.GetAreaUserId(r.USERID, r.UserType)
  124. if areaUserId == r.USERID {
  125. // 所属机构=自己, 则为机构用户类型
  126. r.UserType = 2
  127. } else {
  128. r.UserType = 7
  129. }
  130. }
  131. if r.UserType == 7 {
  132. sqlId += fmt.Sprintf(" and %v in(s.saleuserid, s.tradeuserid, s.meruserid)", r.USERID)
  133. } else {
  134. sqlId += fmt.Sprintf(" and s.userid = %v", r.USERID)
  135. }
  136. return fmt.Sprintf(sqlId, opType)
  137. }
  138. // GetData 从数据库中查询合同操作申请相关信息, opType 操作申请类型 - 1:点价 2:结算登记 3:款项登记 4:发票登记
  139. func (r *ErmcpOPApplyModel) GetData(opType int32) ([]ErmcpOPApplyModel, error) {
  140. sData := make([]ErmcpOPApplyModel, 0)
  141. e := db.GetEngine()
  142. s := e.SQL(r.buildSql(opType))
  143. if err := s.Find(&sData); err != nil {
  144. logger.GetLogger().Errorf("ermcp query fail:%v", err)
  145. return sData, err
  146. }
  147. for i := range sData {
  148. sData[i].calc()
  149. }
  150. return sData, nil
  151. }