作者 tangxuhui

修复 缓存未命中,导致重复查询

@@ -55,10 +55,12 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user @@ -55,10 +55,12 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user
55 soureData[i]["reserve_type"] = reserveType.Name 55 soureData[i]["reserve_type"] = reserveType.Name
56 } else { 56 } else {
57 reserveTypeId, _ := strconv.Atoi(reserveTypeIdS) 57 reserveTypeId, _ := strconv.Atoi(reserveTypeIdS)
58 - reserveType, err := models.GetChanceReserveTypeById(reserveTypeId)  
59 - if err == nil {  
60 - reserveTypeCache[reserveTypeIdS] = reserveType  
61 - soureData[i]["reserve_type"] = reserveType.Name 58 + if reserveTypeId > 0 {
  59 + reserveType, err := models.GetChanceReserveTypeById(reserveTypeId)
  60 + if err == nil {
  61 + reserveTypeCache[reserveTypeIdS] = reserveType
  62 + soureData[i]["reserve_type"] = reserveType.Name
  63 + }
62 } 64 }
63 } 65 }
64 chanceTypeIdS := fmt.Sprint(soureData[i]["chance_type_id"]) 66 chanceTypeIdS := fmt.Sprint(soureData[i]["chance_type_id"])
@@ -67,10 +69,12 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user @@ -67,10 +69,12 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user
67 soureData[i]["chance_type"] = chanceType.Name 69 soureData[i]["chance_type"] = chanceType.Name
68 } else { 70 } else {
69 chanceTypeId, _ := strconv.Atoi(chanceTypeIdS) 71 chanceTypeId, _ := strconv.Atoi(chanceTypeIdS)
70 - chanceType, err := models.GetChanceTypeById(chanceTypeId)  
71 - if err == nil {  
72 - chanceTypeCache[chanceTypeIdS] = chanceType  
73 - soureData[i]["chance_type"] = chanceType.Name 72 + if chanceTypeId > 0 {
  73 + chanceType, err := models.GetChanceTypeById(chanceTypeId)
  74 + if err == nil {
  75 + chanceTypeCache[chanceTypeIdS] = chanceType
  76 + soureData[i]["chance_type"] = chanceType.Name
  77 + }
74 } 78 }
75 } 79 }
76 auditTemplateIdS := fmt.Sprint(soureData[i]["audit_template_id"]) 80 auditTemplateIdS := fmt.Sprint(soureData[i]["audit_template_id"])
@@ -79,10 +83,12 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user @@ -79,10 +83,12 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user
79 soureData[i]["audit_template"] = auditTempalte.Name 83 soureData[i]["audit_template"] = auditTempalte.Name
80 } else { 84 } else {
81 auditTemplateId, _ := strconv.ParseInt(auditTemplateIdS, 10, 64) 85 auditTemplateId, _ := strconv.ParseInt(auditTemplateIdS, 10, 64)
82 - auditTempalte, err := models.GetAuditTemplateById(auditTemplateId)  
83 - if err == nil {  
84 - auditTemplateCache[auditTemplateIdS] = auditTempalte  
85 - soureData[i]["audit_template"] = auditTempalte.Name 86 + if auditTemplateId > 0 {
  87 + auditTempalte, err := models.GetAuditTemplateById(auditTemplateId)
  88 + if err == nil {
  89 + auditTemplateCache[auditTemplateIdS] = auditTempalte
  90 + soureData[i]["audit_template"] = auditTempalte.Name
  91 + }
86 } 92 }
87 } 93 }
88 departmentIdS := fmt.Sprint(soureData[i]["department_id"]) 94 departmentIdS := fmt.Sprint(soureData[i]["department_id"])
@@ -90,10 +96,12 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user @@ -90,10 +96,12 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user
90 soureData[i]["department"] = department.Name 96 soureData[i]["department"] = department.Name
91 } else { 97 } else {
92 departmentId, _ := strconv.ParseInt(departmentIdS, 10, 64) 98 departmentId, _ := strconv.ParseInt(departmentIdS, 10, 64)
93 - department, err := models.GetDepartmentById(departmentId)  
94 - if err == nil {  
95 - departmentCache[departmentIdS] = department  
96 - soureData[i]["department"] = department.Name 99 + if departmentId > 0 {
  100 + department, err := models.GetDepartmentById(departmentId)
  101 + if err == nil {
  102 + departmentCache[departmentIdS] = department
  103 + soureData[i]["department"] = department.Name
  104 + }
97 } 105 }
98 } 106 }
99 reviewStatusS := fmt.Sprint(soureData[i]["review_status"]) 107 reviewStatusS := fmt.Sprint(soureData[i]["review_status"])