@Resource
NurLearningTimeMapper nurLearningTimeMapper;
@Resource
NurStudentMapper nurStudentMapper;
@Resource
NurScoreDetailMapper nurScoreDetailMapper;
private static final long nh = 1000 * 60 * 60;
private static final long nm = 1000 * 60;
@Override
public Result todayTime(StuIdStatusDTO stuIdStatusDTO) throws ParseException {
//获取当前日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, 1);//-1.昨天时间 0.当前时间 1.明天时间 *以此类推
String tomorrow = sdf.format(c.getTime());
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
stuIdStatusDTO.setDate(today);
stuIdStatusDTO.setTomorrow(tomorrow);
List<NurLearningTime> nurStuLearnTimeVOSOne = nurLearningTimeMapper.selectTodayTimeOne(stuIdStatusDTO);
NurLearningTime nurStuLearnTimeVOSTwo = nurLearningTimeMapper.selectTodayTimeTwo(stuIdStatusDTO);
NurStudent nurStudent = nurStudentMapper.selectOne(Wrappers.lambdaQuery(NurStudent.class)
.eq(NurStudent::getStuId, stuIdStatusDTO.getStuId()));
if(nurStuLearnTimeVOSTwo==null){
long duration = 0;
for (NurLearningTime nurLearningTime : nurStuLearnTimeVOSOne) {
long startTime = nurLearningTime.getStartTime().getTime();
long stopTime = nurLearningTime.getStopTime().getTime();
long time = stopTime - startTime;
duration += time;
}
long min = duration / nm;
Double stuStudyTime = nurStudent.getStuStudyTime();
Double stuStudyAllTime = stuStudyTime +min;
nurStudentMapper.update(nurStudent,Wrappers.lambdaUpdate(NurStudent.class)
.set(NurStudent::getStuStudyTime,stuStudyAllTime)
.eq(NurStudent::getStuId,stuIdStatusDTO.getStuId()));
return Result.ok().data("min",min);
}else {
long duration = 0;
for (NurLearningTime nurLearningTime : nurStuLearnTimeVOSOne) {
long startTime = nurLearningTime.getStartTime().getTime();
long stopTime = nurLearningTime.getStopTime().getTime();
long time = stopTime - startTime;
duration += time;
}
long minOne = duration / nm;
long stopTime = nurStuLearnTimeVOSTwo.getStopTime().getTime();
SimpleDateFormat sdfOne = new SimpleDateFormat("yyyy-MM-dd ");
long overTime = (stopTime - (sdfOne.parse(sdfOne.format(stopTime)).getTime()));
long min1 = overTime/nm;
Double stuStudyAllTimeTwo = Double.valueOf(minOne + min1);
nurStudentMapper.update(nurStudent,Wrappers.lambdaUpdate(NurStudent.class)
.set(NurStudent::getStuStudyTime,stuStudyAllTimeTwo)
.eq(NurStudent::getStuId,stuIdStatusDTO.getStuId()));
return Result.ok().data("min1",min1);
}
}