浏览代码

班级不允许添加学员在有效期内

change 4 年之前
父节点
当前提交
b411a9fbc6

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/order/mapper/OrderMapper.java

@@ -5,6 +5,7 @@ import com.zhongzheng.modules.order.bo.OrderQueryBo;
 import com.zhongzheng.modules.order.domain.Order;
 import com.zhongzheng.modules.order.vo.OrderGoodsVo;
 import com.zhongzheng.modules.order.vo.OrderListVo;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -16,4 +17,6 @@ import java.util.List;
  */
 public interface OrderMapper extends BaseMapper<Order> {
     List<OrderListVo> selectList(OrderQueryBo bo);
+
+    Integer selectUserClass(@Param("goodsId") Long goodsId,@Param("userId") Long userId);
 }

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

@@ -257,6 +257,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
      * @return
      */
     public boolean arrangeGrade(String goodsName,Long goodsId,Long orderGoodsId,Long gradeId,Long userId){
+        //查询该学员有没有有效期内同商品班级 有就不允许添加
+        Integer classNum = baseMapper.selectUserClass(goodsId,userId);
+        if (classNum > 0){
+            throw new CustomException("该学员已在此商品有效期内的班级,无法加入新的有效期班级,请查看该学员此商品下的班级");
+        }
         System.out.println("进入创建班级"+gradeId);
         //指定班级
         if(gradeId!=null){

+ 13 - 0
zhongzheng-system/src/main/resources/mapper/modules/order/OrderMapper.xml

@@ -131,5 +131,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ORDER BY o.order_id DESC
     </select>
 
+    <select id="selectUserClass" parameterType="map" resultType="integer">
+        SELECT
+            COUNT(cg.grade_id)
+        FROM
+            class_grade_goods cgg
+                LEFT JOIN class_grade_user cgu ON cgu.grade_id = cgg.grade_id
+                LEFT JOIN class_grade cg ON cg.grade_id = cgg.grade_id
+        WHERE cgg.goods_id =#{goodsId}
+          and cgu.user_id=#{userId}
+          and cg.`status` =1
+          and unix_timestamp(now()) BETWEEN cg.class_start_time and cg.class_end_time
+    </select>
+
 
 </mapper>