作者 tangxuhui

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

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