Parcourir la source

修改云教室课程扣费记录相关功能

hgw il y a 3 ans
Parent
commit
3883387e9f

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantAssetsInfoDao.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ym.mec.biz.dal.entity.TenantAssetsInfo;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -16,5 +17,6 @@ public interface TenantAssetsInfoDao extends BaseMapper<TenantAssetsInfo> {
 
     int insertBatch(@Param("entities") List<TenantAssetsInfo> entities);
 
+    int updateAmount(BigDecimal frozenAmount);
 }
 

+ 11 - 21
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantAssetsInfoServiceImpl.java

@@ -16,7 +16,6 @@ import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.thirdparty.yqpay.DateUtils;
 import org.apache.commons.collections.CollectionUtils;
-import org.redisson.api.RBucket;
 import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,7 +28,6 @@ import java.math.MathContext;
 import java.math.RoundingMode;
 import java.text.ParseException;
 import java.util.*;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -62,13 +60,6 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
     public void courseDeductionRules(List<CourseSchedule> dto) {
         Integer tenantId = TenantContextHolder.getTenantId();
 
-        //防止重复点击 加锁
-        String key = "Tenant_Course_Deduct:" + tenantId;
-        RBucket<Object> bucket = redissonClient.getBucket(key);
-        //原子操作 抢锁成功为true
-        if (!bucket.trySet(tenantId, 1L, TimeUnit.MINUTES)) {
-            throw new BizException("有人正在排课请勿同时操作!");
-        }
         //校验课程 筛选出线上课
         dto = getOnlineCourse(dto);
         if (CollectionUtils.isEmpty(dto)) {
@@ -78,7 +69,7 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
         TenantAssetsInfo assetsInfo = this.getOne(new WrapperUtil<TenantAssetsInfo>()
                 .hasEq("tenant_id_", tenantId).queryWrapper());
         if (Objects.isNull(assetsInfo)) {
-            throw new BizException("未查询到该机构的账户资产信息!");
+            throw new BizException("未查询到该账户资产信息!");
         }
 
         //获取云教室规则  String人数-BigDecimal每分钟扣费标准
@@ -90,17 +81,14 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
             //获取每分钟扣费标准
             BigDecimal minutePrice = rule.get(String.valueOf(totalPeople));
             if (Objects.isNull(minutePrice)) {
-                throw new BizException("该机构未设置 " + totalPeople + " 人(含老师)的课程收费标准,请前往机构产品设置中确认该人数的设置是否存在!");
+                //实际上是没有这个扣费标准
+                throw new BizException("课程人数已达上限,请联系教务老师!");
             }
             //计算总上课时间
             BigDecimal courseDate = getCourseDate(course);
             //课程单价 = 每分钟扣费标准 * 总上课时间
             BigDecimal coursePrice = minutePrice.multiply(courseDate, new MathContext(2, RoundingMode.HALF_UP));
             frozenAmount = frozenAmount.add(coursePrice);
-            //判断余额是否足够
-            if (assetsInfo.getBalance().compareTo(frozenAmount) < 0) {
-                throw new BizException("余额不足!");
-            }
 
             //写入流水
             TenantCloudCourseRecord record = new TenantCloudCourseRecord();
@@ -113,10 +101,12 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
             tenantCloudCourseRecordService.save(record);
         }
 
-        assetsInfo.setBalance(assetsInfo.getBalance().subtract(frozenAmount));
-        assetsInfo.setFrozenAmount(frozenAmount.add(assetsInfo.getFrozenAmount()));
-        this.updateById(assetsInfo);
-        bucket.delete();
+        //直接修改余额,利用数据库的规则来防ABA的出现
+        if (baseMapper.updateAmount(frozenAmount) != 1) {
+            //可能是余额不足
+            throw new BizException("线上课预约火爆,请联系教务老师!");
+        }
+
     }
 
     private List<CourseSchedule> getOnlineCourse(List<CourseSchedule> dto) {
@@ -133,13 +123,13 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
         TenantConfig tenantConfig = tenantConfigService.getOne(new WrapperUtil<TenantConfig>()
                 .hasEq("tenant_id_", tenantId).queryWrapper());
         if (Objects.isNull(tenantConfig)) {
-            throw new BizException("未查询到机构云教室规则信息!");
+            throw new BizException("未查询到云教室规则信息!");
         }
         return Optional.ofNullable(tenantConfig.getConfig())
                 .map(c -> JSON.parseObject(c, TenantConfigDetail.class))
                 .map(TenantConfigDetail::getCloud_room_rule)
                 .map(CloudRoomRule::getCloud_room_config)
-                .orElseThrow(() -> new BizException("未查询到机构云教室规则!"));
+                .orElseThrow(() -> new BizException("未查询到云教室规则!"));
     }
 
     private BigDecimal getCourseDate(CourseSchedule course) {

+ 0 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantCloudCourseRecordServiceImpl.java

@@ -25,16 +25,10 @@ public class TenantCloudCourseRecordServiceImpl extends ServiceImpl<TenantCloudC
 
     private final static Logger logger = LoggerFactory.getLogger(TenantCloudCourseRecordServiceImpl.class);
 
-
     @Override
     public PageInfo<TenantCloudCourseRecordVo> queryPage(Map<String, Object> param) {
         Page<TenantCloudCourseRecordVo> pageInfo = PageUtil.getPageInfo(param);
         pageInfo.setAsc("a.created_time_");
-        if (param.containsKey("startDate")) {
-            String startDate = String.valueOf(param.get("startDate"));
-        }
-//        "classDate  startTime endTime"
-
         return PageUtil.pageInfo(baseMapper.queryPage(pageInfo, param));
 
     }

+ 7 - 0
mec-biz/src/main/resources/config/mybatis/TenantAssetsInfoMapper.xml

@@ -25,4 +25,11 @@
         </foreach>
     </insert>
 
+    <update id="updateAmount" parameterType="decimal">
+        update tenant_assets_info
+        set balance_       = balance_ - #{frozenAmount},
+            frozen_amount_ = frozen_amount_ + #{frozenAmount}
+        where balance_  <![CDATA[ >= ]]> #{frozenAmount}
+    </update>
+
 </mapper>

+ 5 - 8
mec-biz/src/main/resources/config/mybatis/TenantCloudCourseRecordMapper.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.ym.mec.biz.dal.com.ym.mec.biz.dal.dao.TenantCloudCourseRecordDao">
+<mapper namespace="com.ym.mec.biz.dal.dao.TenantCloudCourseRecordDao">
 
     <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.TenantCloudCourseRecord">
         <id column="id_" jdbcType="INTEGER" property="id"/>
@@ -65,14 +65,11 @@
             <if test="param.deductState != null ">
                 AND a.deduct_state_ = #{param.deductState}
             </if>
-            <if test="param.classDate != null ">
-                AND b.class_date_ = #{param.classDate}
+            <if test="param.startDate != null">
+                AND b.class_date_ <![CDATA[ >= ]]>  #{param.startDate}
             </if>
-            <if test="param.startTime != null">
-                AND b.start_class_time_ <![CDATA[ >= ]]>  #{param.startTime}
-            </if>
-            <if test="param.endTime != null ">
-                AND b.`end_class_time_` <![CDATA[ <= ]]>  #{param.endTime}
+            <if test="param.endDate != null ">
+                AND b.`class_date_` <![CDATA[ <= ]]>  #{param.endDate}
             </if>
         </where>
     </select>

+ 27 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TenantCloudCourseRecordController.java

@@ -3,10 +3,17 @@ package com.ym.mec.web.controller;
 
 import com.ym.mec.biz.service.TenantCloudCourseRecordService;
 import com.ym.mec.common.controller.BaseController;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.Map;
 
 /**
  * 机构云教室课程扣费记录(TenantCloudCourseRecord)表控制层
@@ -23,5 +30,25 @@ public class TenantCloudCourseRecordController extends BaseController {
     @Resource
     private TenantCloudCourseRecordService tenantCloudCourseRecordService;
 
+
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "search", dataType = "String", value = "关键字"),
+            @ApiImplicitParam(name = "type", dataType = "String", value = "课程类型"),
+            @ApiImplicitParam(name = "teacherName", dataType = "String", value = "上课教师名称"),
+            @ApiImplicitParam(name = "teacherId", dataType = "Integer", value = "上课教师id"),
+            @ApiImplicitParam(name = "status", dataType = "String", value = "课程状态"),
+            @ApiImplicitParam(name = "deductState", dataType = "Integer", value = "扣费状态 0冻结 1扣费 2取消冻结"),
+            @ApiImplicitParam(name = "startDate", dataType = "String", value = "课程开始日期-年月日"),
+            @ApiImplicitParam(name = "endDate", dataType = "String", value = "课程结束日期-年月日"),
+            @ApiImplicitParam(name = "page", dataType = "Integer", value = "页数"),
+            @ApiImplicitParam(name = "rows", dataType = "Integer", value = "每页数量"),
+    })
+    @ApiOperation("分页查询")
+    @PostMapping(value = "/queryPage")
+//    @PreAuthorize("@pcs.hasPermissions('tenantCloudCourseRecord/queryPage')")
+    public Object queryPage(@RequestBody Map<String, Object> param) {
+        return succeed(tenantCloudCourseRecordService.queryPage(param));
+    }
+
 }