111
wang-hao-jie
2022-08-25 d90da0759bd93c7f429f6a20bc835782ad927c02
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.boying.controller;
 
import com.boying.common.BaseController;
import com.boying.common.util.StringUtil;
import com.boying.entity.*;
import com.boying.service.DeptService;
import com.boying.service.StudyDataService;
import com.boying.service.StudyRecordService;
import com.boying.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
 
@RestController
@RequestMapping("studyRecord")
public class StudyRecordController extends BaseController {
 
    @Autowired
    private StudyRecordService studyRecordService;
    @Autowired
    private StudyDataService studyRecord;
    @Autowired
    private UserService userService;
    @Autowired
    private StudyDataService studyDataService;
 
    @PostMapping("findPage")
    public Object findPage(String name,int page,int pageSize) {
        Pageable pageable = PageRequest.of(page-1,pageSize, Sort.Direction.DESC,"id");
        Page<StudyRecord> pages = studyRecordService.findPageHaveLike(pageable,1,"userName",name);
        return success("",pages);
    }
 
    @PostMapping("findPage2")
    public Object findPage2(Long userId,Long studyId) {
        Pageable pageable = PageRequest.of(0,20, Sort.Direction.DESC,"id");
        Page<StudyRecord>  userId1 = studyRecordService.findPage(pageable, "userId", userId);
        if(studyId!=null){
            userId1 = studyRecordService.findPage(pageable, "userId", userId,"studyId",studyId);
        }
        return success("",userId1.getContent());
    }
 
    @PostMapping("save")
    public Object save(Long id,Long userId,Integer flag,Integer time) {
        if(flag!=null){
            if (flag==0) {
                return success("");
            }
        }
 
        StudyData studyData = (StudyData) studyDataService.findById(id);
        double time2 = studyData.getTime2()*60;//需要学习的分钟时长
 
 
        StudyRecord studyRecord = studyRecordService.findByUserIdAndStudyId(userId,id);
 
        User user = (User) userService.findById(userId);
        int flag2 = 0;
        if(studyRecord==null){
            studyRecord = new StudyRecord();
            studyRecord.setStudyId(id);
            studyRecord.setUserId(userId);
            studyRecord.setStudyName(studyData.getName());
            studyRecord.setUserName(user.getName());
            if(time==null){
                time=1;
                studyRecord.setTime(1);
            }
            studyRecord.setTime(time);
            studyRecord.setType(studyData.getFileType());
 
            if(time>=time2){//判断是否已经学够时长了
                flag2++;
            }
        }else{
            studyRecord.setTime(studyRecord.getTime()+time);
            if(studyRecord.getStatus()==0){//status=0,还没学完
                if(studyRecord.getTime()>=time2){//判断是否已经学够时长了
                    flag2++;
                }
            }
        }
        if(flag2>0){
            studyRecord.setStatus(1);//学完的状态
            studyRecord.setXueShi(studyData.getTime());
 
            user.setSumTime(user.getSumTime()+(int)studyData.getTime());
            userService.save(user);
        }
        studyRecordService.save(studyRecord);
        return success("保存成功");
    }
}