Browse Source

云教室相关功能

hgw 3 years ago
parent
commit
83d8e257c8
17 changed files with 674 additions and 44 deletions
  1. 3 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/PlatformProductDao.java
  2. 22 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantCloudCourseRecordDao.java
  3. 15 7
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/CourseSchedule.java
  4. 134 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantCloudCourseRecord.java
  5. 169 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/vo/TenantCloudCourseRecordVo.java
  6. 21 0
      mec-biz/src/main/java/com/ym/mec/biz/service/TenantCloudCourseRecordService.java
  7. 3 3
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/EmployeeServiceImpl.java
  8. 0 1
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrderPayOpsServiceImpl.java
  9. 13 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/PlatformProductServiceImpl.java
  10. 106 27
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantAssetsInfoServiceImpl.java
  11. 42 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantCloudCourseRecordServiceImpl.java
  12. 1 3
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java
  13. 23 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantProductInfoServiceImpl.java
  14. 13 1
      mec-biz/src/main/resources/config/mybatis/PlatformProductMapper.xml
  15. 2 2
      mec-biz/src/main/resources/config/mybatis/TeacherMapper.xml
  16. 80 0
      mec-biz/src/main/resources/config/mybatis/TenantCloudCourseRecordMapper.xml
  17. 27 0
      mec-web/src/main/java/com/ym/mec/web/controller/TenantCloudCourseRecordController.java

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/PlatformProductDao.java

@@ -21,4 +21,7 @@ public interface PlatformProductDao extends BaseMapper<PlatformProduct> {
     <T> IPage<T> queryPage(Page<T> page, @Param("search") String search);
 
     List<String> queryMenuIdList(Integer serveId);
+
+    List<Integer> queryProductInTenant(Integer id);
+
 }

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

@@ -0,0 +1,22 @@
+package com.ym.mec.biz.dal.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ym.mec.biz.dal.entity.TenantCloudCourseRecord;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Map;
+
+/**
+ * 机构云教室课程扣费记录(TenantCloudCourseRecord)表数据库访问层
+ *
+ * @author hgw
+ * @since 2021-12-26 21:53:20
+ */
+public interface TenantCloudCourseRecordDao extends BaseMapper<TenantCloudCourseRecord> {
+
+    <T> IPage<T> queryPage(Page<T> page, @Param("param") Map<String, Object> param);
+
+}
+

+ 15 - 7
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/CourseSchedule.java

@@ -30,12 +30,20 @@ public class CourseSchedule  extends BaseEntity{
 
 	public enum CourseScheduleType implements BaseEnum<String, CourseScheduleType> {
 
-		SINGLE("SINGLE", "声部课"), MIX("MIX", "合奏课"), HIGH("HIGH", "小班课"), VIP("VIP", "vip课"),
-		DEMO("DEMO", "试听课"), COMPREHENSIVE("COMPREHENSIVE", "综合课"), PRACTICE(
-				"PRACTICE", "网管课"), ENLIGHTENMENT("ENLIGHTENMENT", "启蒙课"), TRAINING_SINGLE("TRAINING_SINGLE", "集训声部课"),
-		TRAINING_MIX("TRAINING_MIX", "集训合奏课"), CLASSROOM(
-				"CLASSROOM", "课堂课"),COMM("COMM","对外课程"),HIGH_ONLINE("HIGH_ONLINE","网络基础训练课"),
-		MUSIC_NETWORK("MUSIC_NETWORK","乐团网管课");
+        SINGLE("SINGLE", "声部课"),
+        MIX("MIX", "合奏课"),
+        HIGH("HIGH", "小班课"),
+        VIP("VIP", "vip课"),
+        DEMO("DEMO", "试听课"),
+        COMPREHENSIVE("COMPREHENSIVE", "综合课"),
+        PRACTICE("PRACTICE", "网管课"),
+        ENLIGHTENMENT("ENLIGHTENMENT", "启蒙课"),
+        TRAINING_SINGLE("TRAINING_SINGLE", "集训声部课"),
+        TRAINING_MIX("TRAINING_MIX", "集训合奏课"),
+        CLASSROOM("CLASSROOM", "课堂课"),
+        COMM("COMM", "对外课程"),
+        HIGH_ONLINE("HIGH_ONLINE", "网络基础训练课"),
+        MUSIC_NETWORK("MUSIC_NETWORK", "乐团网管课");
 
 		private String code;
 
@@ -156,7 +164,7 @@ public class CourseSchedule  extends BaseEntity{
 	private Integer isLock = 0;
 
 	private Integer organId;
-	
+
 	private Organization organization = new Organization();
 
 	private YesOrNoEnum isCallNames;

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

@@ -0,0 +1,134 @@
+package com.ym.mec.biz.dal.entity;
+
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+import java.io.Serializable;
+
+/**
+ * 机构云教室课程扣费记录(TenantCloudCourseRecord)表实体类
+ *
+ * @author hgw
+ * @since 2021-12-26 21:54:10
+ */
+@ApiModel(value = "tenant_cloud_course_record-机构云教室课程扣费记录")
+public class TenantCloudCourseRecord implements Serializable {
+    @TableId(value = "id_", type = IdType.AUTO)
+    @ApiModelProperty(value = "流水id")
+    private Integer id;
+
+    @TableField("tenant_id_")
+    @ApiModelProperty(value = "机构id")
+    private Integer tenantId;
+
+    @TableField("course_id_")
+    @ApiModelProperty(value = "course_schedule表的id_")
+    private Integer courseId;
+
+    @TableField("deduct_state_")
+    @ApiModelProperty(value = "扣费状态 0冻结 1扣费 2取消冻结")
+    private Integer deductState;
+
+    @TableField("amount_")
+    @ApiModelProperty(value = "金额")
+    private BigDecimal amount;
+
+    @TableField("created_by_")
+    @ApiModelProperty(value = "创建人")
+    private Integer createdBy;
+
+    @TableField("created_time_")
+    @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() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(Integer tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    public Integer getCourseId() {
+        return courseId;
+    }
+
+    public void setCourseId(Integer courseId) {
+        this.courseId = courseId;
+    }
+
+    public Integer getDeductState() {
+        return deductState;
+    }
+
+    public void setDeductState(Integer deductState) {
+        this.deductState = deductState;
+    }
+
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public void setAmount(BigDecimal amount) {
+        this.amount = amount;
+    }
+
+    public Integer getCreatedBy() {
+        return createdBy;
+    }
+
+    public void setCreatedBy(Integer createdBy) {
+        this.createdBy = createdBy;
+    }
+
+    public Date getCreatedTime() {
+        return createdTime;
+    }
+
+    public void setCreatedTime(Date createdTime) {
+        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;
+    }
+
+}
+

+ 169 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/vo/TenantCloudCourseRecordVo.java

@@ -0,0 +1,169 @@
+package com.ym.mec.biz.dal.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ym.mec.biz.dal.entity.CourseSchedule;
+import com.ym.mec.biz.dal.enums.CourseStatusEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author hgw
+ * Created by 2021-12-26
+ */
+public class TenantCloudCourseRecordVo implements Serializable {
+    @TableId(value = "id_", type = IdType.AUTO)
+    @ApiModelProperty(value = "流水id")
+    private Integer id;
+
+    @TableField("course_id_")
+    @ApiModelProperty(value = "课程编号 course_schedule表的id_")
+    private Integer courseId;
+
+    @ApiModelProperty(value = "分部名称")
+    private Integer organName;
+
+    @ApiModelProperty(value = "机构名称")
+    private Integer tenantName;
+
+    @ApiModelProperty(value = "课程类型  CourseSchedule.CourseScheduleType")
+    private String type;
+
+    @ApiModelProperty(value = "上课教师名称")
+    private String teacherName;
+
+    @ApiModelProperty(value = "实际上课人数")
+    private Integer studentNum;
+
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @ApiModelProperty(value = "上课日期")
+    private Date classDate;
+
+    @JsonFormat(pattern = "HH:mm:ss")
+    @ApiModelProperty(value = "上课时间")
+    private Date startClassTime;
+
+    @JsonFormat(pattern = "HH:mm:ss")
+    @ApiModelProperty(value = "结束时间")
+    private Date endClassTime;
+
+    @ApiModelProperty(value = "课程状态 CourseStatusEnum")
+    private String status;
+
+    @TableField("deduct_state_")
+    @ApiModelProperty(value = "扣费状态 0冻结 1扣费 2取消冻结")
+    private Integer deductState;
+
+    @TableField("amount_")
+    @ApiModelProperty(value = "金额")
+    private BigDecimal amount;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getCourseId() {
+        return courseId;
+    }
+
+    public void setCourseId(Integer courseId) {
+        this.courseId = courseId;
+    }
+
+    public Integer getOrganName() {
+        return organName;
+    }
+
+    public void setOrganName(Integer organName) {
+        this.organName = organName;
+    }
+
+    public Integer getTenantName() {
+        return tenantName;
+    }
+
+    public void setTenantName(Integer tenantName) {
+        this.tenantName = tenantName;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getTeacherName() {
+        return teacherName;
+    }
+
+    public void setTeacherName(String teacherName) {
+        this.teacherName = teacherName;
+    }
+
+    public Integer getStudentNum() {
+        return studentNum;
+    }
+
+    public void setStudentNum(Integer studentNum) {
+        this.studentNum = studentNum;
+    }
+
+    public Date getClassDate() {
+        return classDate;
+    }
+
+    public void setClassDate(Date classDate) {
+        this.classDate = classDate;
+    }
+
+    public Date getStartClassTime() {
+        return startClassTime;
+    }
+
+    public void setStartClassTime(Date startClassTime) {
+        this.startClassTime = startClassTime;
+    }
+
+    public Date getEndClassTime() {
+        return endClassTime;
+    }
+
+    public void setEndClassTime(Date endClassTime) {
+        this.endClassTime = endClassTime;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public Integer getDeductState() {
+        return deductState;
+    }
+
+    public void setDeductState(Integer deductState) {
+        this.deductState = deductState;
+    }
+
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public void setAmount(BigDecimal amount) {
+        this.amount = amount;
+    }
+}

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

@@ -0,0 +1,21 @@
+package com.ym.mec.biz.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ym.mec.biz.dal.entity.TenantCloudCourseRecord;
+import com.ym.mec.biz.dal.vo.TenantCloudCourseRecordVo;
+import com.ym.mec.common.page.PageInfo;
+
+import java.util.Map;
+
+/**
+ * 机构云教室课程扣费记录(TenantCloudCourseRecord)表服务接口
+ *
+ * @author hgw
+ * @since 2021-12-26 21:54:10
+ */
+public interface TenantCloudCourseRecordService extends IService<TenantCloudCourseRecord> {
+
+    PageInfo<TenantCloudCourseRecordVo> queryPage(Map<String,Object> param);
+
+}
+

+ 3 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/EmployeeServiceImpl.java

@@ -106,15 +106,15 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee>  imp
 		employeeDao.batchAddEmployeeRole(employee.getId(),employee.getRoleIds(), employee.getTenantId());
 		//添加用户现金账户
 		sysUserCashAccountDao.insert(new SysUserCashAccount(employee.getId(),"CNY"));
-		ImResult imResult = imFeignService.register(new ImUserModel(employee.getId().toString(), employee.getUsername(),null));
-		employee.setImToken(imResult.getToken());
+//		ImResult imResult = imFeignService.register(new ImUserModel(employee.getId().toString(), employee.getUsername(),null));
+//		employee.setImToken(imResult.getToken());
 		teacherDao.updateUser(employee);
 		if(user != null){
 			employee.setAvatar(user.getAvatar());
 		}
 
 		//添加到OA
-		oaUserService.addOaUser(employee);
+//		oaUserService.addOaUser(employee);
 	}
 
 	@Override

+ 0 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrderPayOpsServiceImpl.java

@@ -30,7 +30,6 @@ import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.BiPredicate;
 import java.util.function.Consumer;
 import java.util.function.Function;

+ 13 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PlatformProductServiceImpl.java

@@ -12,9 +12,11 @@ import com.ym.mec.biz.service.PlatformProductService;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageUtil;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
@@ -64,6 +66,11 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
         platformProduct.setUpdatedBy(userId);
         platformProduct.setUpdatedTime(new Date());
         baseMapper.updateByPrimaryKeySelective(platformProduct);
+        //查询哪些机构用了这个产品,需要修改对应的权限
+//        List<Integer> tenantIds = baseMapper.queryProductInTenant(obj.getId());
+//        if(CollectionUtils.isEmpty(tenantIds)){
+//            return;
+//        }
     }
 
     /**
@@ -77,6 +84,12 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
         Integer userId = Optional.ofNullable(sysUserFeignService.queryUserInfo())
                 .map(SysUser::getId)
                 .orElseThrow(() -> new BizException("用户信息获取失败"));
+        //校验哪些机构用了该产品
+        List<Integer> tenantIds = baseMapper.queryProductInTenant(id);
+        if(CollectionUtils.isNotEmpty(tenantIds)){
+            throw new BizException("该产品关联的服务已有机构在使用,无法删除!");
+        }
+
         PlatformProduct platformProduct = new PlatformProduct();
         platformProduct.setId(id);
         platformProduct.setDeleted(1);

+ 106 - 27
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantAssetsInfoServiceImpl.java

@@ -2,20 +2,22 @@ package com.ym.mec.biz.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.TenantAssetsInfoDao;
-import com.ym.mec.biz.dal.entity.CourseSchedule;
-import com.ym.mec.biz.dal.entity.TenantAssetsInfo;
-import com.ym.mec.biz.dal.entity.TenantConfig;
-import com.ym.mec.biz.dal.entity.TenantConfigDetail;
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.entity.TenantConfigDetail.CloudRoomRule;
 import com.ym.mec.biz.dal.enums.TeachModeEnum;
 import com.ym.mec.biz.service.TenantAssetsInfoService;
+import com.ym.mec.biz.service.TenantCloudCourseRecordService;
 import com.ym.mec.biz.service.TenantConfigService;
 import com.ym.mec.common.exception.BizException;
-import com.ym.mec.common.filters.TenantIdThreadLocal;
 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;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,10 +27,9 @@ import org.springframework.transaction.annotation.Transactional;
 import java.math.BigDecimal;
 import java.math.MathContext;
 import java.math.RoundingMode;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
+import java.text.ParseException;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -44,6 +45,12 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
 
     @Autowired
     private TenantConfigService tenantConfigService;
+    @Autowired
+    private SysUserFeignService sysUserFeignService;
+    @Autowired
+    private TenantCloudCourseRecordService tenantCloudCourseRecordService;
+    @Autowired
+    private RedissonClient redissonClient;
 
     /**
      * 排课扣费计算
@@ -53,43 +60,115 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void courseDeductionRules(List<CourseSchedule> dto) {
-        dto = Optional.ofNullable(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)) {
+            return;
+        }
+
+        TenantAssetsInfo assetsInfo = this.getOne(new WrapperUtil<TenantAssetsInfo>()
+                .hasEq("tenant_id_", tenantId).queryWrapper());
+        if (Objects.isNull(assetsInfo)) {
+            throw new BizException("未查询到该机构的账户资产信息!");
+        }
+
+        //获取云教室规则  String人数-BigDecimal每分钟扣费标准
+        Map<String, BigDecimal> rule = getRule(tenantId);
+        BigDecimal frozenAmount = BigDecimal.ZERO;
+
+        for (CourseSchedule course : dto) {//获取总人数 ,+1是算上老师
+            Integer totalPeople = course.getStudentNum() + 1;
+            //获取每分钟扣费标准
+            BigDecimal minutePrice = rule.get(String.valueOf(totalPeople));
+            if (Objects.isNull(minutePrice)) {
+                throw new BizException("该机构未设置 " + totalPeople + " 人(含老师)的课程收费标准,请前往机构产品设置中确认该人数的设置是否存在!");
+            }
+            //计算总上课时间
+            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();
+            record.setCourseId(course.getId().intValue());
+            record.setAmount(coursePrice);
+            record.setTenantId(tenantId);
+            record.setDeductState(0);
+            record.setCreatedBy(getUserId());
+            record.setCreatedTime(new Date());
+            tenantCloudCourseRecordService.save(record);
+        }
+
+        assetsInfo.setBalance(assetsInfo.getBalance().subtract(frozenAmount));
+        assetsInfo.setFrozenAmount(frozenAmount.add(assetsInfo.getFrozenAmount()));
+        this.updateById(assetsInfo);
+        bucket.delete();
+    }
+
+    private List<CourseSchedule> getOnlineCourse(List<CourseSchedule> dto) {
+        return Optional.ofNullable(dto)
                 .filter(CollectionUtils::isNotEmpty)
-                .orElseThrow(() -> new BizException("请传入课程表参数!"))
+                .orElseThrow(() -> new BizException("请传入课程数!"))
                 .stream()
                 .filter(c -> c.getTeachMode().equals(TeachModeEnum.ONLINE))
                 .collect(Collectors.toList());
+    }
 
-        Integer tenantId = TenantContextHolder.getTenantId();
+    private Map<String, BigDecimal> getRule(Integer tenantId) {
+        //查询云教室扣费标准
         TenantConfig tenantConfig = tenantConfigService.getOne(new WrapperUtil<TenantConfig>()
                 .hasEq("tenant_id_", tenantId).queryWrapper());
         if (Objects.isNull(tenantConfig)) {
             throw new BizException("未查询到机构云教室规则信息!");
         }
-        //获取云教室规则
-        Map<String, BigDecimal> rule = Optional.ofNullable(tenantConfig.getConfig())
+        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("未查询到机构云教室规则!"));
-        BigDecimal total = BigDecimal.ZERO;
-//        dto.forEach(course -> {
-//            Integer peopleNum = course.getPeopleNum();
-//            BigDecimal minutePrice = rule.get(String.valueOf(peopleNum));
-//            BigDecimal duration = BigDecimal.valueOf(course.getCourseDuration());
-//            BigDecimal coursePrice = minutePrice.multiply(duration, new MathContext(2, RoundingMode.HALF_UP));
-//
-//        });
+    }
 
-        System.out.println(1);
+    private BigDecimal getCourseDate(CourseSchedule course) {
+        String date = DateUtils.formatDate(course.getClassDate(), DateUtils.YYYY_MM_DD_DEF);
+        Date startDT = getDateTime(date, course.getStartClassTime());
+        Date endDT = getDateTime(date, course.getEndClassTime());
+        //课程结束时间-课程开始时间
+        long durationTime = endDT.getTime() - startDT.getTime();
+        //相差多少分钟
+        int durationMinute = new Long(durationTime / 1000 / 60).intValue();
+        return BigDecimal.valueOf(durationMinute);
+    }
 
-        TenantAssetsInfo assetsInfo = this.getOne(new WrapperUtil<TenantAssetsInfo>()
-                .hasEq("tenant_id_", tenantId).queryWrapper());
-        if (Objects.isNull(assetsInfo)) {
-            throw new BizException("未查询到该机构的账户资产信息!");
+    private Date getDateTime(String dateStr, Date time) {
+        String timeStr = DateUtils.formatDate(time, "HH:mm:ss");
+        String s = dateStr + " " + timeStr;
+        try {
+            return DateUtils.parseDate(s, DateUtils.DATE_WEB_FORMAT);
+        } catch (ParseException e) {
+            throw new BizException("课程时间格式错误!");
         }
     }
 
+    private Integer getUserId() {
+        //修改机构基础信息
+        return Optional.ofNullable(sysUserFeignService.queryUserInfo())
+                .map(SysUser::getId)
+                .orElseThrow(() -> new BizException("用户信息获取失败,请刷新页面或者重新登录!"));
+    }
 
 }
 

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

@@ -0,0 +1,42 @@
+package com.ym.mec.biz.service.impl;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ym.mec.biz.dal.dao.TenantCloudCourseRecordDao;
+import com.ym.mec.biz.dal.entity.TenantCloudCourseRecord;
+import com.ym.mec.biz.dal.vo.TenantCloudCourseRecordVo;
+import com.ym.mec.biz.service.TenantCloudCourseRecordService;
+import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.page.PageUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.util.Map;
+
+/**
+ * 机构云教室课程扣费记录(TenantCloudCourseRecord)表服务实现类
+ *
+ * @author hgw
+ * @since 2021-12-26 21:54:10
+ */
+@Service("tenantCloudCourseRecordService")
+public class TenantCloudCourseRecordServiceImpl extends ServiceImpl<TenantCloudCourseRecordDao, TenantCloudCourseRecord> implements TenantCloudCourseRecordService {
+
+    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));
+
+    }
+}
+

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

@@ -285,7 +285,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         String key = "Tenant_First_Open:" + tenantId;
         RBucket<Object> bucket = redissonClient.getBucket(key);
         //原子操作 抢锁成功为true
-        if (!bucket.trySet(tenantId, 1L, TimeUnit.MINUTES)) {
+        if (!bucket.trySet(tenantId, 3L, TimeUnit.SECONDS)) {
             throw new BizException("机构正在开通中请勿频繁操作");
         }
         //获取产品信息得到服务id
@@ -317,8 +317,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         assetsInfo.setFrozenAmount(BigDecimal.ZERO);
         assetsInfo.setCreatedTime(new Date());
         assetsInfoService.save(assetsInfo);
-        //修改机构userId信息
-        baseMapper.updateById(tenantInfo);
         //释放锁
         bucket.delete();
     }

+ 23 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantProductInfoServiceImpl.java

@@ -4,10 +4,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ym.mec.biz.dal.dao.TenantProductInfoDao;
 import com.ym.mec.biz.dal.dto.TenantProductInfoDto;
 import com.ym.mec.biz.dal.entity.TenantProductInfo;
+import com.ym.mec.biz.service.PlatformServeDetailService;
+import com.ym.mec.biz.service.PlatformServeService;
 import com.ym.mec.biz.service.TenantProductInfoService;
+import com.ym.mec.common.exception.BizException;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Optional;
+
 /**
  * @author hgw
  * Created by 2021-12-02
@@ -15,11 +21,17 @@ import org.springframework.stereotype.Service;
 @Service
 public class TenantProductInfoServiceImpl extends ServiceImpl<TenantProductInfoDao, TenantProductInfo> implements TenantProductInfoService {
 
+    @Autowired
+    private PlatformServeService platformServeService;
+    @Autowired
+    private PlatformServeDetailService platformServeDetailService;
+
     /**
      * 添加机构选购的产品信息
      */
     @Override
     public void addTenantProduct(TenantProductInfoDto dto) {
+        checkServe(dto.getServeId(), dto.getServeDetailId());
         TenantProductInfo info = new TenantProductInfo();
         BeanUtils.copyProperties(dto, info);
         baseMapper.insert(info);
@@ -27,10 +39,21 @@ public class TenantProductInfoServiceImpl extends ServiceImpl<TenantProductInfoD
 
     @Override
     public void updateTenantProduct(TenantProductInfoDto dto) {
+        checkServe(dto.getServeId(), dto.getServeDetailId());
         TenantProductInfo info = new TenantProductInfo();
         BeanUtils.copyProperties(dto, info);
         baseMapper.updateById(info);
     }
 
+    private void checkServe(Integer id, Integer detailId) {
+        Optional.ofNullable(id)
+                .map(platformServeService::getById)
+                .orElseThrow(() -> new BizException("未查询到该服务!"));
+
+        Optional.ofNullable(detailId)
+                .map(platformServeDetailService::getById)
+                .orElseThrow(() -> new BizException("未查询到该服务模式!"));
+    }
+
 
 }

+ 13 - 1
mec-biz/src/main/resources/config/mybatis/PlatformProductMapper.xml

@@ -149,5 +149,17 @@
             a.deleted_ = 0 AND b.deleted_ = 0
           AND a.`id_` = #{serveId}
     </select>
-    
+
+    <select id="queryProductInTenant" parameterType="integer" resultType="integer">
+        SELECT
+            DISTINCT
+            tpi.tenant_id_
+        FROM
+            tenant_product_info as tpi
+                JOIN `platform_serve` AS a on tpi.serve_id_ = a.id_
+                JOIN `platform_product` AS b
+                     ON FIND_IN_SET(b.`id_`, a.`product_id_`)
+        where b.id_ = #{id}
+    </select>
+
 </mapper>

+ 2 - 2
mec-biz/src/main/resources/config/mybatis/TeacherMapper.xml

@@ -148,9 +148,9 @@
     <insert id="addSysUser" parameterType="com.ym.mec.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
         INSERT INTO sys_user
-        (tenant_id_,im_token_,id_,username_,salt_,phone_,avatar_,organ_id_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,password_,tenant_id_)
+        (tenant_id_,im_token_,id_,username_,salt_,phone_,avatar_,organ_id_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,password_)
         VALUES(#{tenantId},#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},#{organId},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
-        #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{password},#{tenantId})
+        #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{password})
     </insert>
 
     <!-- 根据主键查询一条记录 -->

+ 80 - 0
mec-biz/src/main/resources/config/mybatis/TenantCloudCourseRecordMapper.xml

@@ -0,0 +1,80 @@
+<?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">
+
+    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.TenantCloudCourseRecord">
+        <id column="id_" jdbcType="INTEGER" property="id"/>
+        <result column="tenant_id_" jdbcType="INTEGER" property="tenantId"/>
+        <result column="course_id_" jdbcType="INTEGER" property="courseId"/>
+        <result column="deduct_state_" jdbcType="INTEGER" property="deductState"/>
+        <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_
+    </sql>
+
+    <select id="queryPage" parameterType="map" resultType="com.ym.mec.biz.dal.vo.TenantCloudCourseRecordVo">
+        select a.id_ as id,
+        b.id_ as courseId,
+        o.name_ as organName,
+        t.name_ as tenantName,
+        b.type_ as type,
+        s.real_name_ as teacherName,
+        b.student_num_ as studentNum,
+        b.class_date_ as classDate,
+        b.start_class_time_ as startClassTime,
+        b.end_class_time_ as endClassTime,
+        b.status_ as `status`,
+        a.deduct_state_ as deductState,
+        a.amount_ as amount
+        from
+        tenant_info as t
+        join tenant_cloud_course_record as a
+        on t.id_ = a.tenant_id_
+        left join course_schedule as b
+        on a.course_id_ = b.id_
+        left join sys_user as s
+        on b.teacher_id_ = s.id_
+        left join organization as o
+        on o.id_ = b.organ_id_
+        <where>
+            <if test="param.search != null ">
+                AND (
+                b.`id_` LIKE CONCAT('%', #{param.search},'%')
+                OR b.`name_` LIKE CONCAT('%', #{param.search},'%')
+                )
+            </if>
+            <if test="param.type != null ">
+                AND b.type_ = #{param.type}
+            </if>
+            <if test="param.teacherName != null ">
+                AND s.real_name_ = #{param.teacherName}
+            </if>
+            <if test="param.teacherId!= null ">
+                AND b.teacher_id_ = #{param.teacherId}
+            </if>
+            <if test="param.status != null ">
+                AND b.status_ = #{param.status}
+            </if>
+            <if test="param.deductState != null ">
+                AND a.deduct_state_ = #{param.deductState}
+            </if>
+            <if test="param.classDate != null ">
+                AND b.class_date_ = #{param.classDate}
+            </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>
+        </where>
+    </select>
+
+</mapper>

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

@@ -0,0 +1,27 @@
+package com.ym.mec.web.controller;
+
+
+import com.ym.mec.biz.service.TenantCloudCourseRecordService;
+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;
+
+/**
+ * 机构云教室课程扣费记录(TenantCloudCourseRecord)表控制层
+ *
+ * @author hgw
+ * @since 2021-12-26 21:53:20
+ */
+@RestController
+@RequestMapping("/tenantCloudCourseRecord")
+public class TenantCloudCourseRecordController extends BaseController {
+    /**
+     * 服务对象
+     */
+    @Resource
+    private TenantCloudCourseRecordService tenantCloudCourseRecordService;
+
+}
+