|
|
@@ -1,17 +1,23 @@
|
|
|
package com.train.controller.admin;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.train.common.Result;
|
|
|
import com.train.entity.TrainSalon;
|
|
|
import com.train.entity.TrainEnrollment;
|
|
|
import com.train.entity.TrainSalonCheckin;
|
|
|
import com.train.entity.TrainSalonFeedback;
|
|
|
+import com.train.entity.TrainUser;
|
|
|
import com.train.mapper.TrainSalonMapper;
|
|
|
import com.train.mapper.TrainEnrollmentMapper;
|
|
|
import com.train.mapper.TrainSalonCheckinMapper;
|
|
|
import com.train.mapper.TrainSalonFeedbackMapper;
|
|
|
+import com.train.mapper.TrainUserMapper;
|
|
|
import com.train.cfc.entity.CfcActivity;
|
|
|
+import com.train.cfc.entity.CfcActivityRegistration;
|
|
|
import com.train.cfc.mapper.CfcActivityMapper;
|
|
|
+import com.train.cfc.mapper.CfcActivityRegistrationMapper;
|
|
|
+import com.train.service.SalonCfcSyncService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
@@ -19,6 +25,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Tag(name = "管理端-沙龙", description = "沙龙管理")
|
|
|
@@ -36,6 +43,12 @@ public class AdminSalonController {
|
|
|
private TrainSalonCheckinMapper trainSalonCheckinMapper;
|
|
|
@Resource
|
|
|
private TrainSalonFeedbackMapper trainSalonFeedbackMapper;
|
|
|
+ @Resource
|
|
|
+ private CfcActivityRegistrationMapper cfcActivityRegistrationMapper;
|
|
|
+ @Resource
|
|
|
+ private TrainUserMapper trainUserMapper;
|
|
|
+ @Resource
|
|
|
+ private SalonCfcSyncService salonCfcSyncService;
|
|
|
|
|
|
private static final List<String> OCCUPY_STATUS = Arrays.asList("pending", "paid", "confirmed");
|
|
|
|
|
|
@@ -67,41 +80,18 @@ public class AdminSalonController {
|
|
|
price = 6800;
|
|
|
}
|
|
|
}
|
|
|
-// 开始时间:优先 yyyy-MM-dd HH:mm:ss,其次 yyyy-MM-dd,解析失败留空
|
|
|
- Date startAt = null;
|
|
|
- if (body.get("startAt") != null && !body.get("startAt").toString().trim().isEmpty()) {
|
|
|
- String startAtStr = body.get("startAt").toString().trim();
|
|
|
- try {
|
|
|
- startAt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startAtStr);
|
|
|
- } catch (ParseException e) {
|
|
|
- try {
|
|
|
- startAt = new SimpleDateFormat("yyyy-MM-dd").parse(startAtStr);
|
|
|
- } catch (ParseException ex) {
|
|
|
- startAt = null;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 结束时间:同 startAt 解析规则,可留空(留空则签到不限结束时间,需手动结束沙龙)
|
|
|
- Date endAt = null;
|
|
|
- if (body.get("endAt") != null && !body.get("endAt").toString().trim().isEmpty()) {
|
|
|
- String endAtStr = body.get("endAt").toString().trim();
|
|
|
- try {
|
|
|
- endAt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endAtStr);
|
|
|
- } catch (ParseException e) {
|
|
|
- try {
|
|
|
- endAt = new SimpleDateFormat("yyyy-MM-dd").parse(endAtStr);
|
|
|
- } catch (ParseException ex) {
|
|
|
- endAt = null;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // 开始/结束时间:统一走 parseSalonDate(显式 Asia/Shanghai,避免 JVM 时区波动导致前后端显示偏移)
|
|
|
+ Date startAt = parseSalonDate(body.get("startAt"));
|
|
|
+ // 结束时间可留空(留空则签到不限结束时间,需手动结束沙龙)
|
|
|
+ Date endAt = parseSalonDate(body.get("endAt"));
|
|
|
TrainSalon salon = new TrainSalon();
|
|
|
salon.setTheme(theme);
|
|
|
salon.setTitle(title);
|
|
|
salon.setTime(time);
|
|
|
salon.setPlace(place);
|
|
|
salon.setCapacity(capacity);
|
|
|
- salon.setStatus("active");
|
|
|
+ // 对齐 cfc 活动流程:新建为草稿,需手动发布后才对外展示/可报名
|
|
|
+ salon.setStatus("draft");
|
|
|
salon.setPrice(price);
|
|
|
salon.setStartAt(startAt);
|
|
|
salon.setEndAt(endAt);
|
|
|
@@ -116,7 +106,8 @@ public class AdminSalonController {
|
|
|
activity.setDescription("爱伴-健康之旅周末沙龙:" + title);
|
|
|
activity.setActivityType("offline");
|
|
|
activity.setDimensionCode("wealth,health,growth");
|
|
|
- activity.setStatus("published");
|
|
|
+ // 与 train_salon 保持同源状态:draft(发布时同步为 published)
|
|
|
+ activity.setStatus("draft");
|
|
|
activity.setAuditStatus("approved");
|
|
|
activity.setLocation(place);
|
|
|
activity.setStartTime(startAt);
|
|
|
@@ -128,6 +119,7 @@ public class AdminSalonController {
|
|
|
activity.setVisibility("restricted");
|
|
|
activity.setCheckinPoints(5);
|
|
|
activity.setPlatformPoints(10);
|
|
|
+ salonCfcSyncService.markSource(activity);
|
|
|
Date syncNow = new Date();
|
|
|
activity.setCreatedAt(syncNow);
|
|
|
activity.setUpdatedAt(syncNow);
|
|
|
@@ -142,6 +134,142 @@ public class AdminSalonController {
|
|
|
return Result.success(salon);
|
|
|
}
|
|
|
|
|
|
+ @Operation(summary = "编辑沙龙")
|
|
|
+ @PostMapping("/update")
|
|
|
+ public Result<TrainSalon> update(@RequestBody Map<String, Object> body) {
|
|
|
+ if (body.get("id") == null) {
|
|
|
+ return Result.error("缺少沙龙ID");
|
|
|
+ }
|
|
|
+ Long id = Long.valueOf(body.get("id").toString());
|
|
|
+ TrainSalon salon = trainSalonMapper.selectById(id);
|
|
|
+ if (salon == null) {
|
|
|
+ return Result.error("沙龙不存在");
|
|
|
+ }
|
|
|
+ if (body.get("title") != null && !body.get("title").toString().trim().isEmpty()) {
|
|
|
+ salon.setTitle(body.get("title").toString().trim());
|
|
|
+ }
|
|
|
+ if (body.containsKey("theme")) {
|
|
|
+ salon.setTheme(emptyToNull(body.get("theme")));
|
|
|
+ }
|
|
|
+ if (body.containsKey("time")) {
|
|
|
+ salon.setTime(emptyToNull(body.get("time")));
|
|
|
+ }
|
|
|
+ if (body.containsKey("place")) {
|
|
|
+ salon.setPlace(emptyToNull(body.get("place")));
|
|
|
+ }
|
|
|
+ if (body.get("capacity") != null) {
|
|
|
+ try {
|
|
|
+ salon.setCapacity(Integer.parseInt(body.get("capacity").toString()));
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (body.get("price") != null) {
|
|
|
+ try {
|
|
|
+ salon.setPrice(Integer.valueOf(body.get("price").toString()));
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (body.containsKey("startAt")) {
|
|
|
+ salon.setStartAt(parseSalonDate(body.get("startAt")));
|
|
|
+ }
|
|
|
+ if (body.containsKey("endAt")) {
|
|
|
+ salon.setEndAt(parseSalonDate(body.get("endAt")));
|
|
|
+ }
|
|
|
+ salon.setUpdatedAt(new Date());
|
|
|
+ // 显式 set:允许把时间/文本字段清空(updateById 默认跳过 null)
|
|
|
+ LambdaUpdateWrapper<TrainSalon> uw = new LambdaUpdateWrapper<>();
|
|
|
+ uw.eq(TrainSalon::getId, id)
|
|
|
+ .set(TrainSalon::getTheme, salon.getTheme())
|
|
|
+ .set(TrainSalon::getTitle, salon.getTitle())
|
|
|
+ .set(TrainSalon::getTime, salon.getTime())
|
|
|
+ .set(TrainSalon::getPlace, salon.getPlace())
|
|
|
+ .set(TrainSalon::getCapacity, salon.getCapacity())
|
|
|
+ .set(TrainSalon::getPrice, salon.getPrice())
|
|
|
+ .set(TrainSalon::getStartAt, salon.getStartAt())
|
|
|
+ .set(TrainSalon::getEndAt, salon.getEndAt())
|
|
|
+ .set(TrainSalon::getUpdatedAt, salon.getUpdatedAt());
|
|
|
+ trainSalonMapper.update(null, uw);
|
|
|
+ // 同步 cfc 活动内容(标题/描述/地点/时间/容量/价格)
|
|
|
+ if (salon.getActivityId() != null) {
|
|
|
+ try {
|
|
|
+ CfcActivity activity = cfcActivityMapper.selectById(salon.getActivityId());
|
|
|
+ if (activity != null) {
|
|
|
+ activity.setTitle(salon.getTitle());
|
|
|
+ activity.setDescription("爱伴-健康之旅周末沙龙:" + salon.getTitle());
|
|
|
+ activity.setLocation(salon.getPlace());
|
|
|
+ activity.setStartTime(salon.getStartAt());
|
|
|
+ activity.setEndTime(salon.getEndAt());
|
|
|
+ activity.setMaxParticipants(salon.getCapacity());
|
|
|
+ activity.setPrice(salon.getPrice());
|
|
|
+ activity.setMemberPrice(salon.getPrice());
|
|
|
+ if (activity.getVendorName() == null) {
|
|
|
+ salonCfcSyncService.markSource(activity);
|
|
|
+ }
|
|
|
+ activity.setUpdatedAt(new Date());
|
|
|
+ LambdaUpdateWrapper<CfcActivity> au = new LambdaUpdateWrapper<>();
|
|
|
+ au.eq(CfcActivity::getId, activity.getId())
|
|
|
+ .set(CfcActivity::getTitle, activity.getTitle())
|
|
|
+ .set(CfcActivity::getDescription, activity.getDescription())
|
|
|
+ .set(CfcActivity::getLocation, activity.getLocation())
|
|
|
+ .set(CfcActivity::getStartTime, activity.getStartTime())
|
|
|
+ .set(CfcActivity::getEndTime, activity.getEndTime())
|
|
|
+ .set(CfcActivity::getMaxParticipants, activity.getMaxParticipants())
|
|
|
+ .set(CfcActivity::getPrice, activity.getPrice())
|
|
|
+ .set(CfcActivity::getMemberPrice, activity.getMemberPrice())
|
|
|
+ .set(CfcActivity::getVendorName, activity.getVendorName())
|
|
|
+ .set(CfcActivity::getUpdatedAt, activity.getUpdatedAt());
|
|
|
+ cfcActivityMapper.update(null, au);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ org.slf4j.LoggerFactory.getLogger(getClass())
|
|
|
+ .warn("同步 cfc 活动内容失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.success(salon);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String emptyToNull(Object value) {
|
|
|
+ if (value == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String s = value.toString().trim();
|
|
|
+ return s.isEmpty() ? null : s;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date parseSalonDate(Object value) {
|
|
|
+ if (value == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String s = value.toString().trim();
|
|
|
+ if (s.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 显式 Asia/Shanghai:前后端以本地时间字符串交互,与展示一致
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
|
|
+ try {
|
|
|
+ return sdf.parse(s);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ sdfDate.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
|
|
+ try {
|
|
|
+ return sdfDate.parse(s);
|
|
|
+ } catch (ParseException ex) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 时间输出统一 Asia/Shanghai 本地字符串(yyyy-MM-dd HH:mm:ss),Map 中 Date 不受实体 @JsonFormat 覆盖 */
|
|
|
+ private String formatTime(Date d) {
|
|
|
+ if (d == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
|
|
+ return sdf.format(d);
|
|
|
+ }
|
|
|
+
|
|
|
@Operation(summary = "沙龙列表")
|
|
|
@PostMapping("/list")
|
|
|
public Result<List<Map<String, Object>>> list(@RequestBody(required = false) Map<String, Object> body) {
|
|
|
@@ -149,6 +277,8 @@ public class AdminSalonController {
|
|
|
new LambdaQueryWrapper<TrainSalon>().orderByDesc(TrainSalon::getId));
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
for (TrainSalon s : salons) {
|
|
|
+ // 以 cfc 活动状态为准回写(cfc 后台结束/下线该活动后,爱伴同步更新)
|
|
|
+ salonCfcSyncService.syncStatusFromActivity(s);
|
|
|
Long occupied = trainEnrollmentMapper.selectCount(
|
|
|
new LambdaQueryWrapper<TrainEnrollment>()
|
|
|
.eq(TrainEnrollment::getSalonId, s.getId())
|
|
|
@@ -185,9 +315,9 @@ public class AdminSalonController {
|
|
|
row.put("occupied", occupied);
|
|
|
row.put("num", num);
|
|
|
row.put("status", s.getStatus());
|
|
|
- row.put("startAt", s.getStartAt());
|
|
|
- row.put("endAt", s.getEndAt());
|
|
|
- row.put("createdAt", s.getCreatedAt());
|
|
|
+ row.put("startAt", formatTime(s.getStartAt()));
|
|
|
+ row.put("endAt", formatTime(s.getEndAt()));
|
|
|
+ row.put("createdAt", formatTime(s.getCreatedAt()));
|
|
|
result.add(row);
|
|
|
}
|
|
|
return Result.success(result);
|
|
|
@@ -244,11 +374,14 @@ TrainSalon salon = trainSalonMapper.selectById(id);
|
|
|
return Result.error("缺少沙龙ID");
|
|
|
}
|
|
|
Long salonId = Long.valueOf(body.get("salonId").toString());
|
|
|
+ TrainSalon salon = trainSalonMapper.selectById(salonId);
|
|
|
List<TrainEnrollment> enrollments = trainEnrollmentMapper.selectList(
|
|
|
new LambdaQueryWrapper<TrainEnrollment>()
|
|
|
.eq(TrainEnrollment::getSalonId, salonId)
|
|
|
.orderByDesc(TrainEnrollment::getId));
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ List<Long> uids = new ArrayList<>();
|
|
|
+ Set<String> enrolledPhones = new HashSet<>();
|
|
|
for (TrainEnrollment e : enrollments) {
|
|
|
Map<String, Object> row = new HashMap<>();
|
|
|
row.put("id", e.getId());
|
|
|
@@ -258,12 +391,67 @@ TrainSalon salon = trainSalonMapper.selectById(id);
|
|
|
row.put("source", e.getSource());
|
|
|
row.put("inviteCode", e.getInviteCode());
|
|
|
row.put("status", e.getStatus());
|
|
|
-row.put("createdAt", e.getCreatedAt());
|
|
|
+ row.put("createdAt", e.getCreatedAt());
|
|
|
result.add(row);
|
|
|
+ if (e.getUid() != null) {
|
|
|
+ uids.add(e.getUid());
|
|
|
+ }
|
|
|
+ if (e.getPhone() != null && !e.getPhone().trim().isEmpty()) {
|
|
|
+ enrolledPhones.add(e.getPhone().trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 合并 cfc 侧报名(仅关联 activity_id 的该沙龙;cfc 新建的活动不进入爱伴)。
|
|
|
+ // 只读合并,不改 cfc 数据;按 cfc_user_id 优先、手机号兜底去重。
|
|
|
+ if (salon != null && salon.getActivityId() != null) {
|
|
|
+ Set<Long> enrolledCfcUserIds = new HashSet<>();
|
|
|
+ if (!uids.isEmpty()) {
|
|
|
+ List<TrainUser> trainUsers = trainUserMapper.selectBatchIds(uids);
|
|
|
+ for (TrainUser u : trainUsers) {
|
|
|
+ if (u.getCfcUserId() != null) {
|
|
|
+ enrolledCfcUserIds.add(u.getCfcUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CfcActivityRegistration> cfcRegs = cfcActivityRegistrationMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<CfcActivityRegistration>()
|
|
|
+ .eq(CfcActivityRegistration::getActivityId, salon.getActivityId())
|
|
|
+ .orderByDesc(CfcActivityRegistration::getId));
|
|
|
+ DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ for (CfcActivityRegistration r : cfcRegs) {
|
|
|
+ boolean duplicate = (r.getUserId() != null && enrolledCfcUserIds.contains(r.getUserId()))
|
|
|
+ || (r.getRegistrantPhone() != null && enrolledPhones.contains(r.getRegistrantPhone().trim()));
|
|
|
+ if (duplicate) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, Object> row = new HashMap<>();
|
|
|
+ row.put("id", "cfc-" + r.getId());
|
|
|
+ row.put("uid", null);
|
|
|
+ row.put("name", r.getRegistrantName());
|
|
|
+ row.put("phone", r.getRegistrantPhone());
|
|
|
+ row.put("source", "cfc");
|
|
|
+ row.put("inviteCode", null);
|
|
|
+ row.put("status", mapCfcRegistrationStatus(r.getStatus()));
|
|
|
+ row.put("cfcStatus", r.getStatus());
|
|
|
+ row.put("createdAt", r.getRegisteredAt() != null
|
|
|
+ ? r.getRegisteredAt().format(fmt)
|
|
|
+ : (r.getCreatedAt() != null ? r.getCreatedAt().format(fmt) : null));
|
|
|
+ result.add(row);
|
|
|
+ }
|
|
|
}
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
+ /** cfc 报名状态 → 爱伴报名状态展示 */
|
|
|
+ private String mapCfcRegistrationStatus(String cfcStatus) {
|
|
|
+ if ("approved".equals(cfcStatus)) {
|
|
|
+ return "confirmed";
|
|
|
+ }
|
|
|
+ if ("rejected".equals(cfcStatus)) {
|
|
|
+ return "rejected";
|
|
|
+ }
|
|
|
+ return "pending";
|
|
|
+ }
|
|
|
+
|
|
|
@Operation(summary = "沙龙签到名单")
|
|
|
@PostMapping("/checkins")
|
|
|
public Result<List<Map<String, Object>>> checkins(@RequestBody Map<String, Object> body) {
|