Browse Source

修改云教室扣费规则相关功能

hgw 3 years ago
parent
commit
ff2f4ec1dd

+ 3 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantAssetsInfoDao.java

@@ -17,6 +17,8 @@ public interface TenantAssetsInfoDao extends BaseMapper<TenantAssetsInfo> {
 
     int insertBatch(@Param("entities") List<TenantAssetsInfo> entities);
 
-    int updateAmount(BigDecimal frozenAmount);
+    int frozenAmount(BigDecimal frozenAmount);
+
+    int recoverAmount(BigDecimal recoverAmount);
 }
 

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantCloudCourseRecordDao.java

@@ -18,5 +18,6 @@ public interface TenantCloudCourseRecordDao extends BaseMapper<TenantCloudCourse
 
     <T> IPage<T> queryPage(Page<T> page, @Param("param") Map<String, Object> param);
 
+    TenantCloudCourseRecord queryLastRecord(Integer courseId);
 }
 

+ 0 - 24
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantCloudCourseRecord.java

@@ -48,14 +48,6 @@ public class TenantCloudCourseRecord implements Serializable {
     @ApiModelProperty(value = "创建时间")
     private Date createdTime;
 
-    @TableField("updated_by_")
-    @ApiModelProperty(value = "更新人")
-    private Integer updatedBy;
-
-    @TableField("updated_time_")
-    @ApiModelProperty(value = "更新时间")
-    private Date updatedTime;
-
     private static final long serialVersionUID = 1L;
 
     public Integer getId() {
@@ -114,21 +106,5 @@ public class TenantCloudCourseRecord implements Serializable {
         this.createdTime = createdTime;
     }
 
-    public Integer getUpdatedBy() {
-        return updatedBy;
-    }
-
-    public void setUpdatedBy(Integer updatedBy) {
-        this.updatedBy = updatedBy;
-    }
-
-    public Date getUpdatedTime() {
-        return updatedTime;
-    }
-
-    public void setUpdatedTime(Date updatedTime) {
-        this.updatedTime = updatedTime;
-    }
-
 }
 

+ 3 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/TenantAssetsInfoService.java

@@ -14,6 +14,8 @@ import java.util.List;
  */
 public interface TenantAssetsInfoService extends IService<TenantAssetsInfo> {
 
-    void courseDeductionRules(List<CourseSchedule> dto);
+    void courseDeductAmountRules(List<CourseSchedule> dto);
+
+    void courseRecoverAmountRules(Integer courseId);
 }
 

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/TenantCloudCourseRecordService.java

@@ -17,5 +17,7 @@ public interface TenantCloudCourseRecordService extends IService<TenantCloudCour
 
     PageInfo<TenantCloudCourseRecordVo> queryPage(Map<String,Object> param);
 
+    TenantCloudCourseRecord queryLastRecord(Integer courseId);
+
 }
 

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -1881,6 +1881,8 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
         if (CollectionUtils.isEmpty(courseSchedules)) {
             return false;
         }
+        //
+
         List<String> classDates = courseSchedules.stream().map(courseSchedule -> DateUtil.dateToString(courseSchedule.getClassDate(), "yyyy-MM-dd"))
                 .collect(Collectors.toList());
 

+ 35 - 7
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.RedissonClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -47,8 +46,30 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
     private SysUserFeignService sysUserFeignService;
     @Autowired
     private TenantCloudCourseRecordService tenantCloudCourseRecordService;
-    @Autowired
-    private RedissonClient redissonClient;
+
+    /**
+     * 恢复/取消 冻结的金额
+     *
+     * @param courseId 课程id
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void courseRecoverAmountRules(Integer courseId) {
+        TenantCloudCourseRecord lastRecord = tenantCloudCourseRecordService.queryLastRecord(courseId);
+        if (Objects.nonNull(lastRecord) && lastRecord.getDeductState() != 0) {
+            //只有冻结的
+            throw new BizException("该课程非线上课!");
+        }
+        //写入流水
+        lastRecord.setDeductState(2);
+        lastRecord.setCreatedBy(getUserId());
+        lastRecord.setCreatedTime(new Date());
+        tenantCloudCourseRecordService.save(lastRecord);
+        //解除冻结金额,恢复余额
+        if (baseMapper.recoverAmount(lastRecord.getAmount()) != 1) {
+            throw new BizException("解除冻结金额失败!");
+        }
+    }
 
     /**
      * 排课扣费计算
@@ -57,7 +78,7 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void courseDeductionRules(List<CourseSchedule> dto) {
+    public void courseDeductAmountRules(List<CourseSchedule> dto) {
         Integer tenantId = TenantContextHolder.getTenantId();
 
         //校验课程 筛选出线上课
@@ -76,12 +97,19 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
         Map<String, BigDecimal> rule = getRule(tenantId);
         BigDecimal frozenAmount = BigDecimal.ZERO;
 
-        for (CourseSchedule course : dto) {//获取总人数 ,+1是算上老师
+        for (CourseSchedule course : dto) {
+            TenantCloudCourseRecord lastRecord = tenantCloudCourseRecordService.queryLastRecord(course.getId().intValue());
+            if (Objects.nonNull(lastRecord) && lastRecord.getDeductState() == 0) {
+                //该课程id最后一条记录也是冻结状态
+                throw new BizException("该课程已是线上课!");
+            }
+
+            //获取总人数 ,+1是算上老师
             Integer totalPeople = course.getStudentNum() + 1;
             //获取每分钟扣费标准
             BigDecimal minutePrice = rule.get(String.valueOf(totalPeople));
             if (Objects.isNull(minutePrice)) {
-                //实际上是没有这个扣费标准
+                //没有这个扣费标准
                 throw new BizException("课程人数已达上限,请联系教务老师!");
             }
             //计算总上课时间
@@ -102,7 +130,7 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
         }
 
         //直接修改余额,利用数据库的规则来防ABA的出现
-        if (baseMapper.updateAmount(frozenAmount) != 1) {
+        if (baseMapper.frozenAmount(frozenAmount) != 1) {
             //可能是余额不足
             throw new BizException("线上课预约火爆,请联系教务老师!");
         }

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

@@ -32,5 +32,10 @@ public class TenantCloudCourseRecordServiceImpl extends ServiceImpl<TenantCloudC
         return PageUtil.pageInfo(baseMapper.queryPage(pageInfo, param));
 
     }
+
+    @Override
+    public TenantCloudCourseRecord queryLastRecord(Integer courseId) {
+        return baseMapper.queryLastRecord(courseId);
+    }
 }
 

+ 9 - 1
mec-biz/src/main/resources/config/mybatis/TenantAssetsInfoMapper.xml

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

+ 14 - 3
mec-biz/src/main/resources/config/mybatis/TenantCloudCourseRecordMapper.xml

@@ -10,13 +10,11 @@
         <result column="amount_" jdbcType="VARCHAR" property="amount"/>
         <result column="created_by_" jdbcType="INTEGER" property="createdBy"/>
         <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
-        <result column="updated_by_" jdbcType="INTEGER" property="updatedBy"/>
-        <result column="updated_time_" jdbcType="TIMESTAMP" property="updatedTime"/>
     </resultMap>
 
     <sql id="Base_Column_List">
         id_
-        , tenant_id_, course_id_, deduct_state_, amount_, created_by_, created_time_, updated_by_, updated_time_
+        , tenant_id_, course_id_, deduct_state_, amount_, created_by_, created_time_
     </sql>
 
     <select id="queryPage" parameterType="map" resultType="com.ym.mec.biz.dal.vo.TenantCloudCourseRecordVo">
@@ -53,6 +51,9 @@
             <if test="param.type != null ">
                 AND b.type_ = #{param.type}
             </if>
+            <if test="param.orgId != null ">
+                AND o.id_= #{param.orgId}
+            </if>
             <if test="param.teacherName != null ">
                 AND s.real_name_ = #{param.teacherName}
             </if>
@@ -74,4 +75,14 @@
         </where>
     </select>
 
+    <select id="queryLastRecord" parameterType="integer" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from
+        tenant_cloud_course_record
+        where course_id_=#{courseId}
+        order by created_time_ desc
+        limit 1
+    </select>
+
 </mapper>

+ 2 - 16
mec-web/src/main/java/com/ym/mec/web/controller/TenantAssetsInfoController.java

@@ -1,16 +1,11 @@
 package com.ym.mec.web.controller;
 
-
-import com.ym.mec.biz.dal.entity.CourseSchedule;
-import com.ym.mec.biz.dal.entity.TenantAssetsInfo;
 import com.ym.mec.biz.service.TenantAssetsInfoService;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import org.springframework.web.bind.annotation.*;
 import com.ym.mec.common.controller.BaseController;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
-import java.util.List;
 
 /**
  * 机构资产信息(TenantAssetsInfo)表控制层
@@ -27,14 +22,5 @@ public class TenantAssetsInfoController extends BaseController {
     @Resource
     private TenantAssetsInfoService tenantAssetsInfoService;
 
-    @ApiOperation("修改机构启用停用状态")
-    @GetMapping(value = "/ops/{id}")
-//    @PreAuthorize("@pcs.hasPermissions('tenantInfo/opsState')")
-    public Object opsState() {
-        tenantAssetsInfoService.courseDeductionRules(null);
-        return succeed();
-    }
-
-
 }