fix(fe): 修社区图片撑破网格;发帖限 3 张;上传偶发失败自动重试 #5
@@ -203,6 +203,7 @@ type Poster struct {
|
|||||||
Age string `json:"age"`
|
Age string `json:"age"`
|
||||||
Weight string `json:"weight"`
|
Weight string `json:"weight"`
|
||||||
Stage string `json:"stage"`
|
Stage string `json:"stage"`
|
||||||
|
Period string `json:"period"` // 报告周期,如 "07.25 - 07.31"
|
||||||
TasksCompleted int64 `json:"tasks_completed"`
|
TasksCompleted int64 `json:"tasks_completed"`
|
||||||
WeightRecords int64 `json:"weight_records"`
|
WeightRecords int64 `json:"weight_records"`
|
||||||
VaccineRecords int64 `json:"vaccine_records"`
|
VaccineRecords int64 `json:"vaccine_records"`
|
||||||
@@ -216,17 +217,23 @@ func (s *Service) GetPoster(userID, petID string) (*Poster, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var tasksDone, weightRecs, vaccineRecs int64
|
// 这是周报告,所有统计按近 7 天算(和报告页「本周概览」口径一致)
|
||||||
|
now := time.Now()
|
||||||
|
weekAgo := now.AddDate(0, 0, -7)
|
||||||
|
|
||||||
|
var tasksDone, weightRecs, vaccineRecs, highRisk int64
|
||||||
s.db.Model(&model.PlanTask{}).
|
s.db.Model(&model.PlanTask{}).
|
||||||
Where("plan_id IN (SELECT id FROM sundynix_plans WHERE pet_id = ?) AND done = ?", petID, true).
|
Where("plan_id IN (SELECT id FROM sundynix_plans WHERE pet_id = ?) AND done = ? AND updated_at >= ?", petID, true, weekAgo).
|
||||||
Count(&tasksDone)
|
Count(&tasksDone)
|
||||||
s.db.Model(&model.HealthRecord{}).Where("pet_id = ? AND type = ?", petID, model.RecordWeight).Count(&weightRecs)
|
s.db.Model(&model.HealthRecord{}).Where("pet_id = ? AND type = ? AND occurred_at >= ?", petID, model.RecordWeight, weekAgo).Count(&weightRecs)
|
||||||
s.db.Model(&model.HealthRecord{}).Where("pet_id = ? AND type = ?", petID, model.RecordVaccine).Count(&vaccineRecs)
|
s.db.Model(&model.HealthRecord{}).Where("pet_id = ? AND type = ? AND occurred_at >= ?", petID, model.RecordVaccine, weekAgo).Count(&vaccineRecs)
|
||||||
|
s.db.Model(&model.HealthRecord{}).Where("pet_id = ? AND type = ? AND category = ? AND occurred_at >= ?", petID, model.RecordSymptom, "高", weekAgo).Count(&highRisk)
|
||||||
|
|
||||||
return &Poster{
|
return &Poster{
|
||||||
PetName: pet.Name, PetEmoji: pet.Emoji, PetAvatarURL: pet.AvatarURL,
|
PetName: pet.Name, PetEmoji: pet.Emoji, PetAvatarURL: pet.AvatarURL,
|
||||||
Age: pet.Age, Weight: pet.Weight, Stage: pet.Stage,
|
Age: pet.Age, Weight: pet.Weight, Stage: pet.Stage,
|
||||||
|
Period: weekAgo.Format("01.02") + " - " + now.Format("01.02"),
|
||||||
TasksCompleted: tasksDone, WeightRecords: weightRecs, VaccineRecords: vaccineRecs,
|
TasksCompleted: tasksDone, WeightRecords: weightRecs, VaccineRecords: vaccineRecs,
|
||||||
HighRiskCount: 0, Headline: "稳定成长",
|
HighRiskCount: highRisk, Headline: "稳定成长",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,10 +261,17 @@ Component({
|
|||||||
ctx.textAlign = 'center';
|
ctx.textAlign = 'center';
|
||||||
ctx.fillStyle = '#8D8277';
|
ctx.fillStyle = '#8D8277';
|
||||||
ctx.font = '24px sans-serif';
|
ctx.font = '24px sans-serif';
|
||||||
ctx.fillText([pet.age, pet.weight, pet.stage].filter(Boolean).join(' | '), W / 2, 268);
|
ctx.fillText([pet.age, pet.weight, pet.stage].filter(Boolean).join(' | '), W / 2, 262);
|
||||||
|
|
||||||
|
// 周报告:显示统计周期,让人知道这四个数是近 7 天的
|
||||||
|
if (p.period) {
|
||||||
|
ctx.fillStyle = '#C7A36A';
|
||||||
|
ctx.font = '22px sans-serif';
|
||||||
|
ctx.fillText('近 7 天 · ' + p.period, W / 2, 298);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.fillStyle = 'rgba(255,255,255,.8)';
|
ctx.fillStyle = 'rgba(255,255,255,.8)';
|
||||||
this.roundRect(ctx, 60, 310, W - 120, 232, 24);
|
this.roundRect(ctx, 60, 316, W - 120, 232, 24);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
const lines = [
|
const lines = [
|
||||||
'完成任务 ' + (p.tasks_completed || 0) + ' 项',
|
'完成任务 ' + (p.tasks_completed || 0) + ' 项',
|
||||||
|
|||||||
Reference in New Issue
Block a user