kobe6258 8 сар өмнө
parent
commit
311fbc8c8a

+ 13 - 0
common/utils/string/string_utils.go

@@ -44,3 +44,16 @@ func RemoveEmptyStrings(slice []string) []string {
 	}
 	return filteredSlice
 }
+
+func UniqueItems(items []string) []string {
+	seen := make(map[string]bool)
+	result := []string{}
+	for _, item := range items {
+		if seen[item] {
+			continue
+		}
+		seen[item] = true
+		result = append(result, item)
+	}
+	return result
+}

+ 11 - 2
domian/report/report_service.go

@@ -77,11 +77,20 @@ type PermissionDTO struct {
 
 func GetGetReportById(reportId int) (ReportDTO ReportDTO, err error) {
 	report, err := reportDao.GetReportById(reportId)
-	if err == nil {
-		ReportDTO = convertReportDTO(report)
+	if err != nil {
+		return
 	}
+	orgId := report.OrgID
+	names, _ := reportDao.GetAuthorByOrgId(orgId)
+	if names != nil && len(names) > 1 {
+		names = stringUtils.UniqueItems(names)
+		report.Author = strings.Join(names, ",")
+	}
+	report.PublishedTime = report.PublishedTime[:10]
+	ReportDTO = convertReportDTO(report)
 	return
 }
+
 func GetTotalPageCount() (total int64) {
 	return reportDao.GetTotalPageCount()
 }

+ 5 - 0
models/report/report.go

@@ -58,6 +58,11 @@ func (t *Report) BeforeCreate(_ *gorm.DB) (err error) {
 	return
 }
 
+func GetAuthorByOrgId(orgId int) (names []string, err error) {
+	db := models.Main()
+	err = db.Model(&Report{}).Select("author").Where("org_id = ?", orgId).Scan(&names).Error
+	return
+}
 func GetReportById(reportId int) (report Report, err error) {
 	db := models.Main()
 	err = db.Select(CommonColumns).Where("id = ?", reportId).First(&report).Error