contractModel.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2020/12/2 9:17
  4. * @Modify : 2020/12/10 10:45
  5. */
  6. // 查询待审核的合同
  7. package models
  8. import (
  9. "fmt"
  10. "mtp2_if/db"
  11. "mtp2_if/logger"
  12. )
  13. // 待审核合同(普通合同)
  14. type AuditContractModel struct {
  15. SpotContractId string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'" binding:"required"` // 合同ID
  16. MatchCustomerName string `json:"matchcustomername" xorm:"'MATCHCUSTOMERNAME'" binding:"required"` // 销售方ID
  17. MatchAccountId string `json:"matchaccountid" xorm:"'MATCHACCOUNTID'"` // 业务员ID
  18. AccountId string `json:"accountid" xorm:"'ACCOUNTID'"` // 交易员ID
  19. CustomerName string `json:"customername" xorm:"'CUSTOMERNAME'"` // 采购方ID
  20. ApplyStatus uint32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 状态
  21. EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
  22. DetailJSON string `json:"detailjson" xorm:"'DETAILJSON'"` // 合同明细
  23. }
  24. // 组装查询普通待审核合同Sql
  25. func (r *AuditContractModel) buildSql(accountIDs string, contractType int32) string {
  26. str := "select to_char(s.spotcontractid) spotcontractid," +
  27. " u.customername," +
  28. " s.accountid," +
  29. " u2.customername matchcustomername," +
  30. " s.customeraccountid matchaccountid," +
  31. " s.signdate," +
  32. " s.applystatus," +
  33. " to_char(s.DETAILJSON) DETAILJSON" +
  34. " from ERMS3_SpotContractApply s" +
  35. " left join userinfo u" +
  36. " on u.userid = s.areauserid" +
  37. " left join userinfo u2" +
  38. " on u2.userid = s.customeruserid" +
  39. " where s.contracttype = %v" +
  40. " and s.applystatus in(0,2)" +
  41. " and s.accountid in(%v)"
  42. return fmt.Sprintf(str, contractType, accountIDs)
  43. }
  44. // 获取待审核的合同
  45. func (r *AuditContractModel) GetData(accountIDs string, contractType int32) ([]AuditContractModel, error) {
  46. sAC := make([]AuditContractModel, 0)
  47. e := db.GetEngine()
  48. s := e.SQL(r.buildSql(accountIDs, contractType))
  49. if err := s.Find(&sAC); err != nil {
  50. logger.GetLogger().Errorf("query pending contract fail:%v", err)
  51. return sAC, err
  52. }
  53. return sAC, nil
  54. }
  55. // 待审核合同(回购)
  56. type AutditContractHGModel struct {
  57. SpotContractId string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'" binding:"required"` // 合同ID
  58. MatchCustomerName string `json:"matchcustomername" xorm:"'MATCHCUSTOMERNAME'" binding:"required"` // 销售方ID
  59. MatchAccountId string `json:"matchaccountid" xorm:"'MATCHACCOUNTID'"` // 业务员ID
  60. AccountId string `json:"accountid" xorm:"'ACCOUNTID'"` // 交易员ID
  61. CustomerName string `json:"customername" xorm:"'CUSTOMERNAME'"` // 采购方ID
  62. WrstandardName string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 商品名称
  63. Wrstandardcode string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 商品代码
  64. ApplyStatus uint32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 状态
  65. EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
  66. ContractQty float64 `json:"contractqty" xorm:"'CONTRACTQTY'"` // 合同量
  67. SignDate string `json:"signdate" xorm:"'SIGNDATE'"` // 签订日期
  68. }
  69. func (r *AutditContractHGModel) buildSql(accountIDs string) string {
  70. sqlId := "select to_char(t.wrrcontractid) spotcontractid," +
  71. " t.accountid," +
  72. " t.contractqty," +
  73. " to_char(t.signdate, 'yyyy-mm-dd') signdate," +
  74. " t.applystatus," +
  75. " w.wrstandardname," +
  76. " w.wrstandardcode," +
  77. " u.accountname customername," +
  78. " u2.accountname matchcustomername," +
  79. " t.customeraccountid matchaccountid," +
  80. " ec.enumdicname" +
  81. " from erms2_wrrapply t" +
  82. " left join wrstandard w" +
  83. " on t.wrstandardid = w.wrstandardid" +
  84. " left join useraccount u" +
  85. " on t.areauserid = u.userid" +
  86. " left join useraccount u2" +
  87. " on t.customeruserid = u2.userid" +
  88. " left join enumdicitem ec" +
  89. " on w.unitid = ec.enumitemname" +
  90. " and ec.enumdiccode = 'goodsunit'" +
  91. " where t.accountid in(%v)" +
  92. " and t.applystatus in (0, 2)"
  93. return fmt.Sprintf(sqlId, accountIDs)
  94. }
  95. // 从数据库获取待审核合同
  96. func (r *AutditContractHGModel) GetData(accountIDs string) ([]AutditContractHGModel, error) {
  97. sAC := make([]AutditContractHGModel, 0)
  98. e := db.GetEngine()
  99. s := e.SQL(r.buildSql(accountIDs))
  100. if err := s.Find(&sAC); err != nil {
  101. logger.GetLogger().Errorf("query hg pending contract fail:%v", err)
  102. return sAC, err
  103. }
  104. return sAC, nil
  105. }
  106. // 待审核基差贸易业务
  107. type PendingAuditBizModel struct {
  108. BizID string `json:"bizid" xorm:"'BIZID'"` // 业务ID
  109. AccountID string `json:"accountid" xorm:"'ACCOUNTID'"` // 现货账户
  110. Type int32 `json:"type" xorm:"'TYPE'"` // 业务类型,1-期现套利,2-仓单回购,3-现货贸易
  111. BizName string `json:"bizname" xorm:"'BIZNAME'"` // 业务名称
  112. AreaName string `json:"areaname" xorm:"'AREANAME'"` // 所属部门
  113. Status int32 `json:"status" xorm:"'STATUS'"` // 状态,0:待审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝
  114. }
  115. func (r *PendingAuditBizModel) buildSql(accIDs string) string {
  116. sqlId := "select t.*, u.accountname AreaName" +
  117. " from (select spottradeid BizID," +
  118. " spottradename BizName," +
  119. " spotaccountid AccountID," +
  120. " 3 as Type," +
  121. " areauserid userId," +
  122. " applystatus Status" +
  123. " from erms2_spottradeapply" +
  124. " union all" +
  125. " select wrrcontractid BizID," +
  126. " wrrcontractname BizName," +
  127. " accountid," +
  128. " 2 as Type," +
  129. " areauserid userId," +
  130. " applystatus Status" +
  131. " from erms2_wrrapply t" +
  132. " union all" +
  133. " select a.asapplyid BizID," +
  134. " a.asname BizName," +
  135. " b.accountid," +
  136. " 1 as Type," +
  137. " a.userid," +
  138. " a.applystatus Status" +
  139. " from erms2_asapply a" +
  140. " inner join erms2_asaccount b" +
  141. " on a.asapplyid = b.asapplyid" +
  142. " and b.taaccountbiztype = 1) t" +
  143. " left join useraccount u" +
  144. " on t.userId = u.userid" +
  145. " where t.Status in (0, 2, 5) and t.accountid in(%v)"
  146. return fmt.Sprintf(sqlId, accIDs)
  147. }
  148. // 从数据库获取待审核基差贸易业务
  149. func (r *PendingAuditBizModel) GetData(accIDs string) ([]PendingAuditBizModel, error) {
  150. sRet := make([]PendingAuditBizModel, 0)
  151. e := db.GetEngine()
  152. s := e.SQL(r.buildSql(accIDs))
  153. if err := s.Find(&sRet); err != nil {
  154. logger.GetLogger().Errorf("query pending biz fail: %v", err)
  155. return nil, err
  156. }
  157. return sRet, nil
  158. }