|
|
@@ -29,6 +29,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -240,6 +242,10 @@ public class EnrollmentController {
|
|
|
row.put("source", e.getSource());
|
|
|
row.put("inviteCode", e.getInviteCode());
|
|
|
row.put("status", e.getStatus());
|
|
|
+ // 学籍(V4.0 §3.4.1):生效时间/有效期 + 派生状态(active/dormant/none)
|
|
|
+ row.put("enrolledAt", e.getEnrolledAt());
|
|
|
+ row.put("validUntil", e.getValidUntil());
|
|
|
+ row.put("enrollmentStatus", enrollmentStatus(e));
|
|
|
row.put("createdAt", e.getCreatedAt());
|
|
|
// 补关联订单号:未关闭订单(unpaid)用于前端继续支付/取消;paid 也回填便于查询
|
|
|
TrainOrder order = trainOrderMapper.selectOne(
|
|
|
@@ -253,4 +259,62 @@ public class EnrollmentController {
|
|
|
}
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 激活休眠学籍(V4.0 §3.4.1):激活费 = 课程费 20%;test 直通成功 → 学籍重新生效 12 个月。
|
|
|
+ */
|
|
|
+ @Operation(summary = "激活休眠学籍")
|
|
|
+ @PostMapping("/activate")
|
|
|
+ public Result<Map<String, Object>> activate(@RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute("userId") Long userId) {
|
|
|
+ if (body.get("enrollmentId") == null) {
|
|
|
+ return Result.error("缺少报名单ID");
|
|
|
+ }
|
|
|
+ Long enrollmentId = Long.valueOf(body.get("enrollmentId").toString());
|
|
|
+ TrainEnrollment en = trainEnrollmentMapper.selectById(enrollmentId);
|
|
|
+ if (en == null || !userId.equals(en.getUid())) {
|
|
|
+ return Result.error("报名单不存在");
|
|
|
+ }
|
|
|
+ if (!"paid".equals(en.getStatus())) {
|
|
|
+ return Result.error("未完成缴费,暂无学籍可激活");
|
|
|
+ }
|
|
|
+ if ("active".equals(enrollmentStatus(en))) {
|
|
|
+ return Result.error("学籍仍有效,无需激活");
|
|
|
+ }
|
|
|
+ // 激活费 = 课程费 20%(分)
|
|
|
+ int activationFee = 0;
|
|
|
+ if (en.getCourseId() != null) {
|
|
|
+ TrainCourse course = trainCourseMapper.selectById(en.getCourseId());
|
|
|
+ if (course != null && course.getPrice() != null) {
|
|
|
+ activationFee = course.getPrice() * 20 / 100;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // test 直通:学籍重新生效 12 个月(正式环境此处需生成激活费订单走支付)
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(new Date());
|
|
|
+ cal.add(Calendar.MONTH, 12);
|
|
|
+ en.setValidUntil(cal.getTime());
|
|
|
+ en.setUpdatedAt(new Date());
|
|
|
+ trainEnrollmentMapper.updateById(en);
|
|
|
+ Map<String, Object> row = new HashMap<>();
|
|
|
+ row.put("enrollmentId", en.getId());
|
|
|
+ row.put("activationFee", activationFee);
|
|
|
+ row.put("validUntil", en.getValidUntil());
|
|
|
+ return Result.success(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 学籍状态派生:paid 且未超期 = active;paid 且已超期 = dormant(休眠);未缴费或无有效期 = none。
|
|
|
+ * 学籍自缴费完成自动建立(PayService 写 enrolledAt/validUntil);paid 但 validUntil 为空(存量数据)
|
|
|
+ * 按 active 处理,避免误导为休眠。
|
|
|
+ */
|
|
|
+ private String enrollmentStatus(TrainEnrollment e) {
|
|
|
+ if (e == null || !"paid".equals(e.getStatus())) {
|
|
|
+ return "none";
|
|
|
+ }
|
|
|
+ if (e.getValidUntil() == null) {
|
|
|
+ return "active";
|
|
|
+ }
|
|
|
+ return e.getValidUntil().after(new Date()) ? "active" : "dormant";
|
|
|
+ }
|
|
|
}
|