作者 tangxuhui

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

... ... @@ -55,47 +55,55 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user
soureData[i]["reserve_type"] = reserveType.Name
} else {
reserveTypeId, _ := strconv.Atoi(reserveTypeIdS)
if reserveTypeId > 0 {
reserveType, err := models.GetChanceReserveTypeById(reserveTypeId)
if err == nil {
reserveTypeCache[reserveTypeIdS] = reserveType
soureData[i]["reserve_type"] = reserveType.Name
}
}
}
chanceTypeIdS := fmt.Sprint(soureData[i]["chance_type_id"])
soureData[i]["chance_type"] = ""
if chanceType, ok := chanceTypeCache[chanceTypeIdS]; ok {
soureData[i]["chance_type"] = chanceType.Name
} else {
chanceTypeId, _ := strconv.Atoi(chanceTypeIdS)
if chanceTypeId > 0 {
chanceType, err := models.GetChanceTypeById(chanceTypeId)
if err == nil {
chanceTypeCache[chanceTypeIdS] = chanceType
soureData[i]["chance_type"] = chanceType.Name
}
}
}
auditTemplateIdS := fmt.Sprint(soureData[i]["audit_template_id"])
soureData[i]["audit_template"] = ""
if auditTempalte, ok := auditTemplateCache[auditTemplateIdS]; ok {
soureData[i]["audit_template"] = auditTempalte.Name
} else {
auditTemplateId, _ := strconv.ParseInt(auditTemplateIdS, 10, 64)
if auditTemplateId > 0 {
auditTempalte, err := models.GetAuditTemplateById(auditTemplateId)
if err == nil {
auditTemplateCache[auditTemplateIdS] = auditTempalte
soureData[i]["audit_template"] = auditTempalte.Name
}
}
}
departmentIdS := fmt.Sprint(soureData[i]["department_id"])
if department, ok := departmentCache[departmentIdS]; ok {
soureData[i]["department"] = department.Name
} else {
departmentId, _ := strconv.ParseInt(departmentIdS, 10, 64)
if departmentId > 0 {
department, err := models.GetDepartmentById(departmentId)
if err == nil {
departmentCache[departmentIdS] = department
soureData[i]["department"] = department.Name
}
}
}
reviewStatusS := fmt.Sprint(soureData[i]["review_status"])
reviewStatus, _ := strconv.ParseInt(reviewStatusS, 10, 8)
soureData[i]["review_status"] = models.ChanceReviewStatusMap[int8(reviewStatus)]
... ...