...
|
...
|
@@ -38,13 +38,77 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user |
|
|
// FROM chance AS a
|
|
|
// JOIN user_company AS c ON c.id = a.user_id
|
|
|
// JOIN user AS d ON c.user_id = d.id
|
|
|
var (
|
|
|
reserveTypeIdMap = map[int]struct{}{}
|
|
|
chanceTypeIdMap = map[int]struct{}{}
|
|
|
auditTemplateIdMap = map[int64]struct{}{}
|
|
|
departmentIdMap = map[int64]struct{}{}
|
|
|
)
|
|
|
for i := range soureData {
|
|
|
reserveTypeIdStr := fmt.Sprint(soureData[i]["reserve_type_id"])
|
|
|
reserveTypeId, _ := strconv.Atoi(reserveTypeIdStr)
|
|
|
reserveTypeIdMap[reserveTypeId] = struct{}{}
|
|
|
chanceTypeIdStr := fmt.Sprint(soureData[i]["chance_type_id"])
|
|
|
chanceTypeId, _ := strconv.Atoi(chanceTypeIdStr)
|
|
|
chanceTypeIdMap[chanceTypeId] = struct{}{}
|
|
|
auditTemplateIdStr := fmt.Sprint(soureData[i]["audit_template_id"])
|
|
|
auditTemplateId, _ := strconv.ParseInt(auditTemplateIdStr, 10, 64)
|
|
|
auditTemplateIdMap[auditTemplateId] = struct{}{}
|
|
|
departmentIdStr := fmt.Sprint(soureData[i]["department_id"])
|
|
|
departmentId, _ := strconv.ParseInt(departmentIdStr, 10, 64)
|
|
|
departmentIdMap[departmentId] = struct{}{}
|
|
|
}
|
|
|
var (
|
|
|
reserveTypeIds []int
|
|
|
chanceTypeIds []int
|
|
|
auditTemplateIds []int64
|
|
|
departmentIds []int64
|
|
|
)
|
|
|
for k := range reserveTypeIdMap {
|
|
|
reserveTypeIds = append(reserveTypeIds, k)
|
|
|
}
|
|
|
for k := range chanceTypeIdMap {
|
|
|
chanceTypeIds = append(chanceTypeIds, k)
|
|
|
}
|
|
|
for k := range auditTemplateIdMap {
|
|
|
auditTemplateIds = append(auditTemplateIds, k)
|
|
|
}
|
|
|
for k := range departmentIdMap {
|
|
|
departmentIds = append(departmentIds, k)
|
|
|
}
|
|
|
var (
|
|
|
reserveTypes []models.ChanceReserveType
|
|
|
chanceTypes []models.ChanceType
|
|
|
auditTemplates []models.AuditTemplate
|
|
|
departments []models.Department
|
|
|
)
|
|
|
reserveTypes, _ = models.GetChanceReserveTypeByIds(reserveTypeIds)
|
|
|
chanceTypes, _ = models.GetChanceTypeByIds(chanceTypeIds)
|
|
|
auditTemplates, _ = models.GetAuditTemplateByIds(auditTemplateIds)
|
|
|
departments, _ = models.GetDepartmentByIds(departmentIds)
|
|
|
//进行数据整理
|
|
|
var (
|
|
|
reserveTypeCache = make(map[string]*models.ChanceReserveType)
|
|
|
chanceTypeCache = make(map[string]*models.ChanceType)
|
|
|
auditTemplateCache = make(map[string]*models.AuditTemplate)
|
|
|
departmentCache = make(map[string]*models.Department)
|
|
|
reserveTypeCache = make(map[string]models.ChanceReserveType)
|
|
|
chanceTypeCache = make(map[string]models.ChanceType)
|
|
|
auditTemplateCache = make(map[string]models.AuditTemplate)
|
|
|
departmentCache = make(map[string]models.Department)
|
|
|
)
|
|
|
for i := range reserveTypes {
|
|
|
idString := strconv.Itoa(reserveTypes[i].Id)
|
|
|
reserveTypeCache[idString] = reserveTypes[i]
|
|
|
}
|
|
|
for i := range chanceTypes {
|
|
|
idString := strconv.Itoa(chanceTypes[i].Id)
|
|
|
chanceTypeCache[idString] = chanceTypes[i]
|
|
|
}
|
|
|
for i := range auditTemplates {
|
|
|
idString := strconv.Itoa(int(auditTemplates[i].Id))
|
|
|
auditTemplateCache[idString] = auditTemplates[i]
|
|
|
}
|
|
|
for i := range departments {
|
|
|
idString := strconv.Itoa(int(departments[i].Id))
|
|
|
departmentCache[idString] = departments[i]
|
|
|
}
|
|
|
for i := range soureData {
|
|
|
storeTypeS := fmt.Sprint(soureData[i]["type"])
|
|
|
storeType, _ := strconv.ParseInt(storeTypeS, 10, 8)
|
...
|
...
|
@@ -53,57 +117,62 @@ func GetAuditListForExcel(param protocol.RequestAuditList, companyid int64, user |
|
|
soureData[i]["reserve_type"] = "未设置"
|
|
|
if reserveType, ok := reserveTypeCache[reserveTypeIdS]; ok {
|
|
|
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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 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"] = ""
|
|
|
//TODO
|
|
|
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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 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)]
|
...
|
...
|
|