fix(report):修正对于园区的最新报表期数的检测。
This commit is contained in:
parent
b09b3f4f2d
commit
e9a122fcda
|
@ -90,7 +90,7 @@ func initializeNewReport(c *gin.Context) {
|
|||
result.NotAccept("提供的初始化期数格式不正确。")
|
||||
return
|
||||
}
|
||||
valid, err := service.ReportService.IsNewPeriodValid(userSession.Uid, reportPeriod)
|
||||
valid, err := service.ReportService.IsNewPeriodValid(userSession.Uid, requestParkId, reportPeriod)
|
||||
if err != nil {
|
||||
result.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
|
|
@ -55,20 +55,20 @@ func (_ReportService) FetchParksWithNewestReport(uid string) ([]model.ParkNewest
|
|||
return lo.Values(reducedParks), nil
|
||||
}
|
||||
|
||||
func (_ReportService) IsNewPeriodValid(uid string, period time.Time) (bool, error) {
|
||||
func (_ReportService) IsNewPeriodValid(uid, pid string, period time.Time) (bool, error) {
|
||||
reports := make([]model.Report, 0)
|
||||
if cachedReport, _ := cache.RetreiveSearch[[]model.Report]("report", "user", uid); cachedReport != nil {
|
||||
if cachedReport, _ := cache.RetreiveSearch[[]model.Report]("report", "user", uid, "park", pid); cachedReport != nil {
|
||||
reports = *cachedReport
|
||||
} else {
|
||||
err := global.DBConn.
|
||||
Table("report").Alias("r").
|
||||
Join("INNER", []string{"park", "p"}, "r.park_id=p.id").
|
||||
Where(builder.Eq{"p.user_id": uid}).
|
||||
Where(builder.Eq{"p.user_id": uid, "r.park_id": pid}).
|
||||
Find(&reports)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
cache.CacheSearch(reports, []string{"report", "park"}, "park", "user", uid)
|
||||
cache.CacheSearch(reports, []string{"report", "park"}, "park", "user", uid, "park", pid)
|
||||
}
|
||||
// 检查给定的期数在目前的记录中是否已经存在
|
||||
exists := lo.Reduce(
|
||||
|
|
Loading…
Reference in New Issue
Block a user