Browse Source

fix 题库

he2802 3 years ago
parent
commit
13f616d930

+ 2 - 11
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseServiceImpl.java

@@ -207,19 +207,10 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
                 } else {
                     goodsPeriodVo.setPeriodStatus(-1L);
                 }
+            }else {
+                goodsPeriodVo.setPeriodStatus(-1L);
             }
         }
-        GoodsPeriodVo goodsPeriodVo = BeanUtil.toBean(goodsPeriodVos.get(0),GoodsPeriodVo.class);
-        goodsPeriodVo.setPeriodStatus(1L);
-        goodsPeriodVos.add(goodsPeriodVo);
-
-        GoodsPeriodVo goodsPeriodVo1 = BeanUtil.toBean(goodsPeriodVos.get(0),GoodsPeriodVo.class);
-        goodsPeriodVo1.setPeriodStatus(2L);
-        goodsPeriodVos.add(goodsPeriodVo1);
-
-        GoodsPeriodVo goodsPeriodVo2 = BeanUtil.toBean(goodsPeriodVos.get(0),GoodsPeriodVo.class);
-        goodsPeriodVo2.setPeriodStatus(3L);
-        goodsPeriodVos.add(goodsPeriodVo2);
         return goodsPeriodVos;
     }
 

+ 6 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/order/service/impl/OrderServiceImpl.java

@@ -223,9 +223,15 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         Map<String, Object> result = new HashMap<>();
         result.put("oderId",add.getOrderId());
         result.put("orderSn",out_trade_no);
+        //发送购买商品成功
+        sendMessage(bo);
         return result;
     }
 
+    private void sendMessage(OrderAddBo bo) {
+        /*if ()*/
+    }
+
     @Override
     public Boolean updateByEditBo(OrderEditBo bo) {
         Order update = BeanUtil.toBean(bo, Order.class);

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/domain/UserStudyRecord.java

@@ -54,4 +54,7 @@ private static final long serialVersionUID=1L;
     private Long goodsId;
     /** 班级ID */
     private Long gradeId;
+
+    /** 绑定计划ID */
+    private Long planId;
 }

+ 8 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/mapper/UserStudyRecordMapper.java

@@ -46,4 +46,12 @@ public interface UserStudyRecordMapper extends BaseMapper<UserStudyRecord> {
     UserPeriodStatus selectPeriodCount(UserStudyRecord entity);
 
     Long userPlanSave(Long goodsId);
+
+    Long userPlanSaveId(Long goodsId);
+
+    Long selectPland(UserStudyRecord bo);
+
+    List<Long> getPlanGoods(Long planId);
+
+    Long selectPlandCount(@Param("goodsId") Long goodsId,@Param("planId") Long planId);
 }

+ 89 - 29
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserStudyRecordServiceImpl.java

@@ -3,11 +3,15 @@ package com.zhongzheng.modules.user.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.microsoft.schemas.office.visio.x2012.main.SectionType;
 import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.modules.bank.domain.Exam;
+import com.zhongzheng.modules.face.service.IFaceService;
+import com.zhongzheng.modules.goods.vo.GoodsUserVo;
 import com.zhongzheng.modules.grade.bo.UserPeriodAddBo;
 import com.zhongzheng.modules.grade.bo.UserPeriodStatusAddBo;
 import com.zhongzheng.modules.grade.domain.UserPeriod;
@@ -16,8 +20,11 @@ import com.zhongzheng.modules.grade.service.IUserPeriodService;
 import com.zhongzheng.modules.grade.service.IUserPeriodStatusService;
 import com.zhongzheng.modules.grade.vo.UserPeriodStatusVo;
 import com.zhongzheng.modules.user.bo.*;
+import com.zhongzheng.modules.user.domain.UserPlan;
 import com.zhongzheng.modules.user.domain.UserStudyRecord;
 import com.zhongzheng.modules.user.mapper.UserStudyRecordMapper;
+import com.zhongzheng.modules.user.service.IUserPlanGoodsService;
+import com.zhongzheng.modules.user.service.IUserPlanService;
 import com.zhongzheng.modules.user.service.IUserStudyRecordPhotoService;
 import com.zhongzheng.modules.user.service.IUserStudyRecordService;
 import com.zhongzheng.modules.user.vo.*;
@@ -30,6 +37,7 @@ import com.github.pagehelper.Page;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -60,11 +68,12 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
     @Autowired
     private IUserPeriodStatusService iUserPeriodStatusService;
 
-
+    @Autowired
+    private IUserPlanService userPlanService;
 
 
     @Override
-    public UserStudyRecordVo queryById(Long recordId){
+    public UserStudyRecordVo queryById(Long recordId) {
         UserStudyRecord db = this.baseMapper.selectById(recordId);
         return BeanUtil.toBean(db, UserStudyRecordVo.class);
     }
@@ -78,7 +87,7 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
         lqw.eq(bo.getGoodsId() != null, UserStudyRecord::getGoodsId, bo.getGoodsId());
         lqw.eq(bo.getModuleId() != null, UserStudyRecord::getModuleId, bo.getModuleId());
         lqw.orderByDesc(UserStudyRecord::getRecordId);
-        return  BeanUtil.toBean(this.getOne(lqw.last("limit 1")), UserStudyRecordVo.class);
+        return BeanUtil.toBean(this.getOne(lqw.last("limit 1")), UserStudyRecordVo.class);
     }
 
     @Override
@@ -99,19 +108,19 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
     }
 
     /**
-    * 实体类转化成视图对象
-    *
-    * @param collection 实体类集合
-    * @return
-    */
+     * 实体类转化成视图对象
+     *
+     * @param collection 实体类集合
+     * @return
+     */
     private List<UserStudyRecordVo> entity2Vo(Collection<UserStudyRecord> collection) {
         List<UserStudyRecordVo> voList = collection.stream()
                 .map(any -> BeanUtil.toBean(any, UserStudyRecordVo.class))
                 .collect(Collectors.toList());
         if (collection instanceof Page) {
-            Page<UserStudyRecord> page = (Page<UserStudyRecord>)collection;
+            Page<UserStudyRecord> page = (Page<UserStudyRecord>) collection;
             Page<UserStudyRecordVo> pageVo = new Page<>();
-            BeanUtil.copyProperties(page,pageVo);
+            BeanUtil.copyProperties(page, pageVo);
             pageVo.addAll(voList);
             voList = pageVo;
         }
@@ -125,11 +134,11 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
         validEntityBeforeSave(add);
         add.setCreateTime(DateUtils.getNowTime());
         add.setUpdateTime(DateUtils.getNowTime());
-        add.setStartTime(DateUtils.getNowTime()-add.getStudyDuration());
+        add.setStartTime(DateUtils.getNowTime() - add.getStudyDuration());
         add.setEndTime(DateUtils.getNowTime());
         this.save(add);
         //新增学时记录,照片
-        userPeriodSave(add,bo);
+        userPeriodSave(add, bo);
         //完成当天学习计划
         userPlanSave(add);
         return 0;
@@ -148,16 +157,16 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
      *
      * @param entity 实体类数据
      */
-    private void validEntityBeforeSave(UserStudyRecord entity){
+    private void validEntityBeforeSave(UserStudyRecord entity) {
         //TODO 做一些数据校验,如唯一约束
     }
 
 
-    private void userPeriodSave(UserStudyRecord entity,UserStudyRecordAddBo bo){
+    private void userPeriodSave(UserStudyRecord entity, UserStudyRecordAddBo bo) {
         //记录学时审核
         Long periodId = null;
         // 学习无记录加一条学时审核记录
-        if (baseMapper.selectStudyRecord(entity) < 1){
+        if (baseMapper.selectStudyRecord(entity) < 1) {
             UserPeriod userPeriod = new UserPeriod();
             userPeriod.setUserId(entity.getUserId());
             userPeriod.setCourseId(entity.getCourseId());
@@ -182,7 +191,7 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
             userPeriodStatusAddBo.setCreateTime(DateUtils.getNowTime());
             userPeriodStatusAddBo.setUpdateTime(DateUtils.getNowTime());
             iUserPeriodStatusService.save(userPeriodStatusAddBo);
-        }else {
+        } else {
             //待审有结束时间跳过下面两步
             if (baseMapper.selectPeriod(entity) < 1) {
                 //有学习记录时审核记录0作弊或3待重修更改为待审核,完整播放也添加结束时间
@@ -197,18 +206,18 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
                     userPeriodStatusAddBo.setRecordStartTime(entity.getStartTime());
                     userPeriodStatusAddBo.setCreateTime(DateUtils.getNowTime());
                     userPeriodStatusAddBo.setUpdateTime(DateUtils.getNowTime());
-                    if (entity.getStatus() != null && entity.getStatus() ==1) {
+                    if (entity.getStatus() != null && entity.getStatus() == 1) {
                         userPeriodStatusAddBo.setRecordEndTime(entity.getEndTime());
                     }
                     iUserPeriodStatusService.save(userPeriodStatusAddBo);
                     periodId = userPeriodStatusAddBo.getId();
-                } else if (userPeriodStatus.getStatus() == 3){
+                } else if (userPeriodStatus.getStatus() == 3) {
                     userPeriodStatus.setPeriodStatus(1);
                     userPeriodStatus.setStatus(2);
                     userPeriodStatus.setRecordStartTime(entity.getStartTime());
                     userPeriodStatus.setCreateTime(DateUtils.getNowTime());
                     userPeriodStatus.setUpdateTime(DateUtils.getNowTime());
-                    if (entity.getStatus() != null && entity.getStatus() ==1) {
+                    if (entity.getStatus() != null && entity.getStatus() == 1) {
                         userPeriodStatus.setRecordEndTime(entity.getEndTime());
                     }
                     iUserPeriodStatusService.updateById(userPeriodStatus);
@@ -239,14 +248,65 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
         }
     }
 
-    private void userPlanSave(UserStudyRecord entity){
+    private void userPlanSave(UserStudyRecord entity) {
         //搜索该用户得商品有没有计划没有跳过,完整播放且计划里没有该学习记录更新学习计划状态
-       // if (baseMapper.userPlanSave(entity.getGoodsId()) > 0){}
+        if (baseMapper.userPlanSave(entity.getGoodsId()) > 0 && entity.getStatus().equals(1)) {
+            Long planId = baseMapper.userPlanSaveId(entity.getGoodsId());
+            entity.setPlanId(planId);
+            if (baseMapper.selectPland(entity) < 1) {
+                this.updateById(entity);
+                List<Long> goodsIds = baseMapper.getPlanGoods(planId);
+                //更新计划
+                UserPlanQueryBo userPlanQueryBo = new UserPlanQueryBo();
+                userPlanQueryBo.setPlanId(planId);
+                userPlanQueryBo.setUserId(entity.getUserId());
+                UserPlanVo userPlanVo = userPlanService.queryById(userPlanQueryBo);
+                Calendar rightNow = Calendar.getInstance();
+                boolean status = true;
+                //得到日历日期
+                List<CalendarStudyVo> calendarStudyVo = userPlanVo.getCalendarStudyVo();
+                calendarStudyVo = calendarStudyVo.stream().filter(CalendarStudyVo -> CalendarStudyVo.getMonth().equals(rightNow.get(Calendar.MONTH) + 1)).collect(Collectors.toList());
+                //对比今天学习的数量是否更新完成
+                if (CollectionUtils.isNotEmpty(calendarStudyVo)) {
+                    for (CalendarStudyVo studyVo : calendarStudyVo) {
+                        List<DayStudyVo> collect = studyVo.getDayStudyList();
+                        collect = studyVo.getDayStudyList().stream().filter(dayStudyVo -> dayStudyVo.getDate().equals(rightNow.get(Calendar.DAY_OF_MONTH))).collect(Collectors.toList());
+                        for (DayStudyVo dayStudyVo : collect) {
+                            for (DaySectionVo daySectionVo : dayStudyVo.getDaySectionList()) {
+                                Long count = baseMapper.selectPlandCount(daySectionVo.getGoodsId(), entity.getPlanId());
+                                if (count < daySectionVo.getStudyGoodsKnob()) {
+                                    status = false;
+                                }
+                            }
+                        }
+                    }
+                    if (status) {
+                        List<CalendarStudyVo> calendarStudyUp = userPlanVo.getCalendarStudyVo();
+                        for (CalendarStudyVo studyVo : calendarStudyUp) {
+                            if (studyVo.getMonth().equals((rightNow.get(Calendar.MONTH) + 1)) && studyVo.getYear().equals(rightNow.get(Calendar.YEAR))) {
+                                for (DayStudyVo dayStudyVo : studyVo.getDayStudyList()) {
+                                    if (dayStudyVo.getDate().equals(Calendar.DAY_OF_MONTH)) {
+                                        dayStudyVo.setPerform(1);
+                                        for (DaySectionVo daySectionVo : dayStudyVo.getDaySectionList()) {
+                                            daySectionVo.setGoodsPerform(1);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                        UserPlan userPlan = new UserPlan();
+                        userPlan.setSchedule(JSON.toJSONString(calendarStudyUp));
+                        userPlan.setPlanId(userPlanVo.getPlanId());
+                        userPlanService.updateById(userPlan);
+                    }
+                }
+            }
+        }
     }
 
     @Override
     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
-        if(isValid){
+        if (isValid) {
             //TODO 做一些业务上的校验,判断是否需要校验
         }
         return this.removeByIds(ids);
@@ -254,7 +314,7 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
 
     @Override
     public List<UserStudyRecord> selectUserStudy(Long userId, Integer courseId) {
-        return baseMapper.selectUserStudy(userId,courseId);
+        return baseMapper.selectUserStudy(userId, courseId);
     }
 
     @Override
@@ -274,20 +334,20 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
                 secLong = new BigDecimal(secLong.toString()).add(new BigDecimal(subjectStudyRecordVo.getSectionNum().toString())).longValue();
                 studyLong = new BigDecimal(studyLong.toString()).add(new BigDecimal(subjectStudyRecordVo.getRecordNum().toString())).longValue();
 
-                if (CollectionUtils.isNotEmpty(baseMapper.sectionType(subjectStudyRecordVo.getCourseId(),1L))){
+                if (CollectionUtils.isNotEmpty(baseMapper.sectionType(subjectStudyRecordVo.getCourseId(), 1L))) {
                     sectionType = sectionType.concat("1,");
                 }
-                if (CollectionUtils.isNotEmpty(baseMapper.sectionType(subjectStudyRecordVo.getCourseId(),2L))){
+                if (CollectionUtils.isNotEmpty(baseMapper.sectionType(subjectStudyRecordVo.getCourseId(), 2L))) {
                     sectionType = sectionType.concat("2,");
                 }
-                if (CollectionUtils.isNotEmpty(baseMapper.sectionType(subjectStudyRecordVo.getCourseId(),3L))){
+                if (CollectionUtils.isNotEmpty(baseMapper.sectionType(subjectStudyRecordVo.getCourseId(), 3L))) {
                     sectionType = sectionType.concat("3,");
                 }
                 if (StringUtils.isNotBlank(sectionType)) {
                     subjectStudyRecordVo.setSectionType(sectionType.substring(0, sectionType.length() - 1));
                 }
             }
-            BigDecimal divide =new BigDecimal("0");
+            BigDecimal divide = new BigDecimal("0");
             if (secLong != 0) {
                 divide = new BigDecimal(studyLong.toString()).divide(new BigDecimal(secLong.toString()), 2, BigDecimal.ROUND_HALF_UP);
             }
@@ -310,7 +370,7 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
     public List<SectionStudyRecordVo> listSection(SubjectStudyRecordQueryBo bo) {
         List<SectionStudyRecordVo> sectionStudyRecordVos = baseMapper.listSection(bo);
         for (SectionStudyRecordVo sectionStudyRecordVo : sectionStudyRecordVos) {
-            if (sectionStudyRecordVo.getStartTime() == null){
+            if (sectionStudyRecordVo.getStartTime() == null) {
                 sectionStudyRecordVo.setStatus(2L);
             }
         }
@@ -330,7 +390,7 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
                 String s = "";
                 for (String examType : examTypes) {
                     if (StringUtils.isNotBlank(examType)) {
-                        s= s.concat(examType + ",");
+                        s = s.concat(examType + ",");
                     }
                 }
                 if (StringUtils.isNotBlank(s)) {

+ 101 - 0
zhongzheng-system/src/main/resources/mapper/modules/user/UserStudyRecordMapper.xml

@@ -627,4 +627,105 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         AND up.user_id = #{userId}
         AND ups.period_status = 1
     </select>
+
+    <select id="userPlanSave" parameterType="Long" resultType="Long">
+        SELECT
+            COUNT(1)
+        FROM
+            user_plan_goods upg
+                LEFT JOIN user_plan up	on upg.plan_id = up.plan_id
+        WHERE
+            upg.source_id = #{goodsId}
+          and up.`status` = 1
+    </select>
+
+    <select id="userPlanSaveId" parameterType="Long" resultType="Long">
+        SELECT
+            upg.plan_id
+        FROM
+            user_plan_goods upg
+                LEFT JOIN user_plan up	on upg.plan_id = up.plan_id
+        WHERE
+            upg.source_id = #{goodsId}
+          and up.`status` = 1
+    </select>
+
+    <select id="selectPland" parameterType="com.zhongzheng.modules.user.domain.UserStudyRecord" resultType="Long">
+        SELECT
+            COUNT( 1 )
+        FROM
+            user_study_record usr
+        WHERE
+            1 = 1
+        <choose>
+            <when test="chapterId != null and chapterId !=''">
+                AND usr.chapter_id = #{chapterId}
+            </when>
+            <otherwise>
+                AND usr.chapter_id = 0
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="sectionId != null and sectionId !=''">
+                AND usr.section_id = #{sectionId}
+            </when>
+            <otherwise>
+                AND usr.section_id = 0
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="moduleId != null and moduleId !=''">
+                AND usr.module_id = #{moduleId}
+            </when>
+            <otherwise>
+                AND usr.module_id = 0
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="courseId != null and courseId !=''">
+                AND usr.course_id = #{courseId}
+            </when>
+            <otherwise>
+                AND usr.course_id = 0
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="gradeId != null and gradeId !=''">
+                AND usr.grade_id = #{gradeId}
+            </when>
+            <otherwise>
+                AND usr.grade_id = 0
+            </otherwise>
+        </choose>
+        <choose>
+            <when test="goodsId != null and goodsId !=''">
+                AND usr.goods_id = #{goodsId}
+            </when>
+            <otherwise>
+                AND usr.goods_id = 0
+            </otherwise>
+        </choose>
+          AND usr.plan_id =1
+    </select>
+
+    <select id="getPlanGoods" parameterType="Long" resultType="Long">
+        SELECT
+            upg.source_id
+        FROM
+            user_plan_goods upg
+                LEFT JOIN user_plan up	on upg.plan_id = up.plan_id
+        WHERE
+            upg.plan_id =#{planId}
+          and up.`status` = 1
+    </select>
+
+    <select id="selectPlandCount" parameterType="map" resultType="Long">
+        SELECT
+            COUNT(1)
+        FROM
+            user_study_record usr
+        WHERE 1=1
+          and usr.plan_id = #{planId}
+          and usr.goods_id = #{goodsId}
+    </select>
 </mapper>