|
@@ -0,0 +1,186 @@
|
|
|
|
|
+package com.ruoyi.web.controller.front;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import com.ruoyi.common.core.content.VistorContextHolder;
|
|
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
|
|
+import com.ruoyi.dz.domain.DzControl;
|
|
|
|
|
+import com.ruoyi.dz.service.IDzControlService;
|
|
|
|
|
+import com.ruoyi.ie.domain.AEnrollUniversity;
|
|
|
|
|
+import com.ruoyi.ie.service.IAEnrollUniversityService;
|
|
|
|
|
+import com.ruoyi.learn.domain.LearnPlan;
|
|
|
|
|
+import com.ruoyi.learn.domain.LearnPlanStudy;
|
|
|
|
|
+import com.ruoyi.learn.service.ILearnPlanService;
|
|
|
|
|
+import com.ruoyi.learn.service.ILearnPlanStudyService;
|
|
|
|
|
+import com.ruoyi.sy.service.ISyMajorService;
|
|
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
+import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.validation.ValidationException;
|
|
|
|
|
+import java.text.ParseException;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.util.Calendar;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/front/student")
|
|
|
|
|
+@Api(tags = "前台-学习-学生")
|
|
|
|
|
+public class FrontStudentController {
|
|
|
|
|
+ private final IDzControlService dzControlService;
|
|
|
|
|
+ private final IAEnrollUniversityService universityService;
|
|
|
|
|
+ private final ISyMajorService syMajorService;
|
|
|
|
|
+ private final ISysUserService sysUserService;
|
|
|
|
|
+ private final ILearnPlanService learnPlanService;
|
|
|
|
|
+ private final ILearnPlanStudyService learnPlanStudyService;
|
|
|
|
|
+
|
|
|
|
|
+ public FrontStudentController(IDzControlService dzControlService, IAEnrollUniversityService universityService, ISyMajorService syMajorService, ISysUserService sysUserService, ILearnPlanService learnPlanService, ILearnPlanStudyService learnPlanStudyService) {
|
|
|
|
|
+ this.dzControlService = dzControlService;
|
|
|
|
|
+ this.universityService = universityService;
|
|
|
|
|
+ this.syMajorService = syMajorService;
|
|
|
|
|
+ this.sysUserService = sysUserService;
|
|
|
|
|
+ this.learnPlanService = learnPlanService;
|
|
|
|
|
+ this.learnPlanStudyService = learnPlanStudyService;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("01 计划院校列表")
|
|
|
|
|
+ @GetMapping(value = "getUniversityList")
|
|
|
|
|
+ public AjaxResult getUniversityList() {
|
|
|
|
|
+ DzControl dzControl = dzControlService.selectDzControl(VistorContextHolder.getContext());
|
|
|
|
|
+ AEnrollUniversity cond = new AEnrollUniversity();
|
|
|
|
|
+ cond.setYear(dzControl.getPlanYear());
|
|
|
|
|
+ return AjaxResult.success(universityService.selectAEnrollUniversityList(cond).stream().map(
|
|
|
|
|
+ t -> JSONObject.of("universityId", t.getUniversityId(), "universityName", t.getUniversityName())
|
|
|
|
|
+ ).collect(Collectors.toList()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("02 计划院校专业及专业组树")
|
|
|
|
|
+ @GetMapping(value = "getGroupMajors")
|
|
|
|
|
+ public AjaxResult getGroupMajors(@ApiParam("院校ID") Long universityId) {
|
|
|
|
|
+ return AjaxResult.success(syMajorService.selectPlanMajorList(VistorContextHolder.getContext(), universityId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("03 查询学生定向院校")
|
|
|
|
|
+ @GetMapping(value = "getDirectionSchools")
|
|
|
|
|
+ public AjaxResult getDirectionSchools() {
|
|
|
|
|
+ SysUser user = sysUserService.selectUserById(SecurityUtils.getLoginUser().getUserId());
|
|
|
|
|
+ return AjaxResult.success(JSONArray.parse(user.getDirectedStudy()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("04 保存学生定向院校")
|
|
|
|
|
+ @PostMapping(value = "saveDirectionSchools")
|
|
|
|
|
+ public AjaxResult saveDirectionSchools(@RequestBody JSONArray directionStudy) {
|
|
|
|
|
+ SysUser user = new SysUser();
|
|
|
|
|
+ user.setUserId(SecurityUtils.getLoginUser().getUserId());
|
|
|
|
|
+ user.setDirectedStudy(directionStudy.toJSONString());
|
|
|
|
|
+ return sysUserService.updateUserProfile(user) > 0 ? AjaxResult.success("更新成功") : AjaxResult.success("无更新");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("10 查询学习计划")
|
|
|
|
|
+ @GetMapping("getLearnPlan")
|
|
|
|
|
+ public AjaxResult getLearnPlan()
|
|
|
|
|
+ {
|
|
|
|
|
+ return AjaxResult.success(getCurrLearnPlan());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("11 保存学习计划")
|
|
|
|
|
+ @PostMapping("saveLearnPlan")
|
|
|
|
|
+ public AjaxResult saveLearnPlan(@RequestBody LearnPlan plan)
|
|
|
|
|
+ {
|
|
|
|
|
+ plan.setStudentId(SecurityUtils.getLoginUser().getUserId());
|
|
|
|
|
+
|
|
|
|
|
+ LearnPlan curr = getCurrLearnPlan();
|
|
|
|
|
+ Date today = DateUtils.truncate(new Date(), Calendar.DATE);
|
|
|
|
|
+ if(curr.getStatus().equals(1)) {
|
|
|
|
|
+ if(DateUtils.isSameDay(curr.getBeginTime(), today)) { // 当天的更新计划
|
|
|
|
|
+ curr.setVideoTime(plan.getVideoTime());
|
|
|
|
|
+ curr.setQuestionCnt(plan.getQuestionCnt());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ curr.setStatus(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ curr.setStudentId(null);
|
|
|
|
|
+ curr.setBeginTime(null);
|
|
|
|
|
+ curr.setStats(null);
|
|
|
|
|
+ learnPlanService.updateLearnPlan(plan);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(curr.getStatus().equals(1)) {
|
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
|
+ }
|
|
|
|
|
+ plan.setStudentId(SecurityUtils.getLoginUser().getUserId());
|
|
|
|
|
+ plan.setBeginTime(today);
|
|
|
|
|
+ plan.setStatus(1);
|
|
|
|
|
+ learnPlanService.insertLearnPlan(plan);
|
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("10 查询学习计划统计")
|
|
|
|
|
+ @GetMapping("getLearnPlanStats")
|
|
|
|
|
+ public AjaxResult getLearnPlanStats(@ApiParam String reportMonth)
|
|
|
|
|
+ {
|
|
|
|
|
+ LearnPlan curr = getCurrLearnPlan();
|
|
|
|
|
+ // 统计每天的学习情况, 再汇总
|
|
|
|
|
+ LearnPlanStudy cond = new LearnPlanStudy();
|
|
|
|
|
+ cond.setStudentId(SecurityUtils.getLoginUser().getUserId());
|
|
|
|
|
+ try {
|
|
|
|
|
+ cond.setReportDate(DateUtils.parseDate(reportMonth, "yyyy-MM-dd"));
|
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
|
+ throw new ValidationException("日期格式错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<LearnPlanStudy> studyList = learnPlanStudyService.selectLearnPlanStudyList(cond);
|
|
|
|
|
+ Integer doneDay = 0;
|
|
|
|
|
+ Long videoTimes = 0L;
|
|
|
|
|
+ Long questionCnt = 0L;
|
|
|
|
|
+ Date today = new Date();
|
|
|
|
|
+ LearnPlanStudy todayStudy = null;
|
|
|
|
|
+ for(LearnPlanStudy study : studyList) {
|
|
|
|
|
+ if(!study.getReportDate().before(today)) { // 今天
|
|
|
|
|
+ doneDay++;
|
|
|
|
|
+ videoTimes += study.getVideoTime();
|
|
|
|
|
+ questionCnt = study.getQuestionCount();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ todayStudy = study;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer preDay = 0;
|
|
|
|
|
+ if(DateUtils.isSameDay(cond.getReportDate(), DateUtils.truncate(curr.getBeginTime(), Calendar.MONTH))) {
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+ cal.setTime(curr.getBeginTime());
|
|
|
|
|
+ preDay = cal.get(Calendar.DAY_OF_MONTH) - 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject stats = new JSONObject();
|
|
|
|
|
+ stats.put("doneDay", doneDay);
|
|
|
|
|
+ stats.put("unDoneDay", LocalDate.now().getDayOfMonth() - doneDay - preDay);
|
|
|
|
|
+ stats.put("videoTimes", videoTimes);
|
|
|
|
|
+ stats.put("questionCnt", questionCnt);
|
|
|
|
|
+ stats.put("studyList", studyList);
|
|
|
|
|
+ stats.put("today", todayStudy);
|
|
|
|
|
+ stats.put("plan", curr);
|
|
|
|
|
+ return AjaxResult.success(stats);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private LearnPlan getCurrLearnPlan() {
|
|
|
|
|
+ LearnPlan cond = new LearnPlan();
|
|
|
|
|
+ cond.setStudentId(SecurityUtils.getLoginUser().getUserId());
|
|
|
|
|
+ cond.setStatus(1);
|
|
|
|
|
+ List<LearnPlan> planList = learnPlanService.selectLearnPlanList(cond);
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(planList)) {
|
|
|
|
|
+ return planList.get(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ cond.setQuestionCnt(90);
|
|
|
|
|
+ cond.setVideoTime(5);
|
|
|
|
|
+ cond.setStatus(0);
|
|
|
|
|
+ cond.setBeginTime(DateUtils.truncate(new Date(), Calendar.DATE));
|
|
|
|
|
+ return cond;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|