ermcpPendingAuditInfo.go 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/2/25 13:32
  4. * @Modify : 2021/2/25 13:32
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. )
  11. // ErmcpPendingAudit 待审核信息
  12. type ErmcpPendingAudit struct {
  13. UserQty int64 `json:"userqty" xorm:"'UserQty'"` // 待审核数量: 用户
  14. SpotContractQty int64 `json:"spotcontractqty" xorm:"'SpotContractQty'"` // 待审核数量: 现货合同
  15. HedgePlanQty int64 `json:"hedgeplanqty" xorm:"'HedgePlanQty'"` // 待审核数量: 套保计划
  16. BusinessDjQty int64 `json:"businessdjqty" xorm:"'BusinessDjQty'"` // 待审核数量: 点价
  17. BusinessJsQty int64 `json:"businessjsqty" xorm:"'BusinessJsQty'"` // 待审核数量: 结算
  18. BusinessKxQty int64 `json:"businesskxqty" xorm:"'BusinessKxQty'"` // 待审核数量: 款项
  19. BusinessFpQty int64 `json:"businessfpqty" xorm:"'BusinessFpQty'"` // 待审核数量: 发票
  20. AreaStockQty int64 `json:"areastockqty" xorm:"'AreaStockQty'"` // 待审核数量: 库存申请
  21. UserId int64 `json:"-"` // 所属用户id
  22. }
  23. // ErmcpPendingAuditQty 待审核数量类型和计数
  24. type ErmcpPendingAuditQty struct {
  25. CntType int64 `json:"CntType" xorm:"'CntType'"` // 类型 1-用户 2-合同 3-套保 4-点价申请 5-结算 6-款项 7-发票
  26. CntQty int64 `json:"CntQty" xorm:"'CntQty'"` // 数量
  27. }
  28. func (r *ErmcpPendingAudit) buildSql() string {
  29. var sqlId = "select 1 as cnttype, count(1) cntqty from wskh_userinfo t where t.memberareaid = %v and t.userstate in(2,4)" +
  30. " union all " +
  31. "select 2, count(1) SpotContractQty from ermcp_spotcontract t where t.userid = %v and t.contractstatus = 1" +
  32. " union all " +
  33. "select 3, count(1) HedgePlanQty from ermcp_hedgeplan t where t.areauserid = %v and t.hedgeplanstatus = 1" +
  34. " union all " +
  35. "select 4, count(1) BusinessDjQty from ermcp_contractoperateapply t where t.userid = %v and t.applystatus = 1 and t.operateapplytype=1" +
  36. " union all " +
  37. "select 5, count(1) BusinessJsQty from ermcp_contractoperateapply t where t.userid = %v and t.applystatus = 1 and t.operateapplytype=2" +
  38. " union all " +
  39. "select 6, count(1) BusinessKxQty from ermcp_contractoperateapply t where t.userid = %v and t.applystatus = 1 and t.operateapplytype=3" +
  40. " union all " +
  41. "select 7, count(1) BusinessFpQty from ermcp_contractoperateapply t where t.userid = %v and t.applystatus = 1 and t.operateapplytype=4" +
  42. " union all " +
  43. "select 8, count(1) AreaStockQty from ermcp_areainoutstockapply t where t.ApplyStatus = 1"
  44. sqlId = fmt.Sprintf(sqlId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId)
  45. return sqlId
  46. }
  47. // GetDataEx 获取小红点计数信息
  48. func (r *ErmcpPendingAudit) GetDataEx() (interface{}, error) {
  49. rspData := make([]ErmcpPendingAudit, 0)
  50. sData := make([]ErmcpPendingAuditQty, 0)
  51. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  52. if err == nil {
  53. var v ErmcpPendingAudit
  54. for _, d := range sData {
  55. // 类型 1-用户 2-合同 3-套保 4-点价申请 5-结算 6-款项 7-发票
  56. switch d.CntType {
  57. case 1:
  58. v.UserQty = d.CntQty
  59. case 2:
  60. v.SpotContractQty = d.CntQty
  61. case 3:
  62. v.HedgePlanQty = d.CntQty
  63. case 4:
  64. v.BusinessDjQty = d.CntQty
  65. case 5:
  66. v.BusinessJsQty = d.CntQty
  67. case 6:
  68. v.BusinessKxQty = d.CntQty
  69. case 7:
  70. v.BusinessFpQty = d.CntQty
  71. case 8:
  72. v.AreaStockQty = d.CntQty
  73. }
  74. }
  75. rspData = append(rspData, v)
  76. }
  77. return rspData, err
  78. }