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("保存成功");
|
}
|
}
|