|
@@ -1,10 +1,20 @@
|
|
|
package com.ynfy.buss.course.usercoursecatalog.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUnit;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ynfy.buss.course.usercoursecatalog.entity.UserCourseCatalog;
|
|
|
+import com.ynfy.buss.course.usercoursecatalog.entity.vo.CatalogTimeVO;
|
|
|
import com.ynfy.buss.course.usercoursecatalog.mapper.UserCourseCatalogMapper;
|
|
|
import com.ynfy.buss.course.usercoursecatalog.service.IUserCourseCatalogService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @Description: 用户课程任务学习情况
|
|
@@ -15,4 +25,38 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class UserCourseCatalogServiceImpl extends ServiceImpl<UserCourseCatalogMapper, UserCourseCatalog> implements IUserCourseCatalogService {
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算任务学习时长
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void calcStudyTime(CatalogTimeVO catalogTimeVO) {
|
|
|
+ if (StringUtils.isBlank(catalogTimeVO.getCourseCatalogId()) || Objects.isNull(catalogTimeVO.getStartLearnTime())
|
|
|
+ || Objects.isNull(catalogTimeVO.getEndLearnTime())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (DateUtil.compare(catalogTimeVO.getEndLearnTime(), catalogTimeVO.getStartLearnTime()) > 0) {
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+
|
|
|
+ UserCourseCatalog courseCatalog = findUserCatalog(sysUser.getId(), catalogTimeVO.getCourseCatalogId());
|
|
|
+ if (Objects.isNull(courseCatalog)) {
|
|
|
+ courseCatalog = new UserCourseCatalog();
|
|
|
+ }
|
|
|
+ courseCatalog.setUserId(sysUser.getId());
|
|
|
+ courseCatalog.setCourseCatalogId(catalogTimeVO.getCourseCatalogId());
|
|
|
+ long between = DateUtil.between(catalogTimeVO.getStartLearnTime(), catalogTimeVO.getEndLearnTime(), DateUnit.SECOND);
|
|
|
+ courseCatalog.setTotalLearnTime(Integer.parseInt(String.valueOf(((!Objects.isNull(courseCatalog.getTotalLearnTime())
|
|
|
+ ? courseCatalog.getTotalLearnTime() : 0) + between))));
|
|
|
+ saveOrUpdate(courseCatalog);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public UserCourseCatalog findUserCatalog(String userId, String courseCatalogId) {
|
|
|
+ LambdaQueryWrapper<UserCourseCatalog> query = new LambdaQueryWrapper<UserCourseCatalog>()
|
|
|
+ .eq(UserCourseCatalog::getUserId, userId).eq(UserCourseCatalog::getCourseCatalogId, courseCatalogId);
|
|
|
+ return getOne(query);
|
|
|
+ }
|
|
|
}
|