cy 3 anni fa
parent
commit
0b8ea0dcd0

+ 5 - 0
cooleshow-common/src/main/java/com/yonge/cooleshow/common/constant/SysConfigConstant.java

@@ -174,4 +174,9 @@ public interface SysConfigConstant {
 
     /** 老师分享曲目二维码跳转链接 */
     String TEACHER_MUSIC_SHEET_SHARE_URL = "teacher_music_sheet_share_url";
+
+    /**
+     * 琴房课扣时公式
+     */
+    String PIANO_ROOM_TIME_FORMULA = "piano_room_time_formula";
 }

+ 12 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/CourseScheduleRecord.java

@@ -47,6 +47,18 @@ public class CourseScheduleRecord implements Serializable {
     @ApiModelProperty(value = "更新时间")
     private Date updatedTime;
 
+    @TableField(exist = false)
+    @ApiModelProperty(value = "单课时长")
+    private Integer singleCourseTime;
+
+    public Integer getSingleCourseTime() {
+        return singleCourseTime;
+    }
+
+    public void setSingleCourseTime(Integer singleCourseTime) {
+        this.singleCourseTime = singleCourseTime;
+    }
+
     public Date getEndTime() {
         return endTime;
     }

+ 20 - 4
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CourseScheduleServiceImpl.java

@@ -44,6 +44,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
@@ -1527,7 +1530,7 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
         List<CourseScheduleStudentVo> userList = paymentDao.selectUser();
         if (CollectionUtils.isNotEmpty(userList)) {
             List<CourseScheduleStudentVo> practiceList = userList.stream().filter(s -> s.getType().equals(CourseScheduleEnum.PRACTICE.getCode())).collect(Collectors.toList());
-            if(CollectionUtils.isNotEmpty(practiceList)){//添加陪练课评论
+            if (CollectionUtils.isNotEmpty(practiceList)) {//添加陪练课评论
                 repliedDao.insertBatch(practiceList);
             }
 
@@ -1542,11 +1545,20 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
             List<CourseScheduleRecord> recordList = recordDao.sumCourseTime();
             if (CollectionUtils.isNotEmpty(recordList)) {
                 //时长消费记录
-                recordDao.insertBatch(recordList);
+                String formula = sysConfigService.findConfigValue(SysConfigConstant.PIANO_ROOM_TIME_FORMULA);
+                List<CourseScheduleRecord> records = recordList.stream()
+                        .map(s -> {
+                            Integer studentCount = s.getStudentCount();
+                            Integer n = (Integer) WrapperUtil.strToFormula(formula, "n", String.valueOf(studentCount + 1));
+                            s.setConsumTime(s.getSingleCourseTime() * n);
+                            return s;
+                        })
+                        .collect(Collectors.toList());
+                recordDao.insertBatch(records);
 
                 //释放冻结课时
                 List<PianoRoomTime> roomTimeList = new ArrayList<>();
-                Map<Long, List<CourseScheduleRecord>> collect = recordList.stream().collect(Collectors.groupingBy(CourseScheduleRecord::getTeacherId, Collectors.toList()));
+                Map<Long, List<CourseScheduleRecord>> collect = records.stream().collect(Collectors.groupingBy(CourseScheduleRecord::getTeacherId, Collectors.toList()));
                 collect.forEach((key, list) -> {
                     PianoRoomTime pianoRoomTime = pianoRoomTimeDao.selectOne(Wrappers.<PianoRoomTime>lambdaQuery().eq(PianoRoomTime::getTeacherId, key));
                     Integer frozenTime = pianoRoomTime.getFrozenTime();
@@ -1651,7 +1663,11 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
         Integer classNum = arrangeCourseVo.getClassNum();//课时数
         Integer singleClssTime = arrangeCourseVo.getSingleClssTime();//单课时长
         List<Long> studentIds = arrangeCourseVo.getStudentIds();//学员id集合
-        Integer consumTime = classNum * singleClssTime * studentIds.size();//消耗时长
+
+        String formula = sysConfigService.findConfigValue(SysConfigConstant.PIANO_ROOM_TIME_FORMULA);
+        Integer n = (Integer) WrapperUtil.strToFormula(formula, "n", String.valueOf(studentIds.size() + 1));//人数计算 公式n*(n-1) n包含老师
+        Integer consumTime = classNum * singleClssTime * n;//消耗时长 课程数*单课时长*人数
+
         List<CourseTimeEntity> timeList = arrangeCourseVo.getTimeList();//选课时间
         Integer consumeTime = arrangeCourseVo.getConsumeTime();
 

+ 20 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/support/WrapperUtil.java

@@ -4,7 +4,11 @@ import com.alibaba.fastjson.JSONObject;
 import com.yonge.toolset.base.exception.BizException;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.formula.functions.T;
 
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
@@ -268,4 +272,20 @@ public class WrapperUtil {
         return map;
     }
 
+    /**
+     * 字符串转公式
+     * @param formula 公式字符串
+     * @param variable 变量
+     * @param param 参数
+     * @return
+     */
+    public static Object strToFormula(String formula, String variable, String param){
+        ScriptEngine jse = new ScriptEngineManager().getEngineByName("JavaScript");
+        try {
+            return jse.eval(formula.replace(variable, param));
+        } catch (ScriptException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 }

+ 12 - 19
cooleshow-user/user-biz/src/main/resources/config/mybatis/CourseScheduleRecordMapper.xml

@@ -3,25 +3,18 @@
 <mapper namespace="com.yonge.cooleshow.biz.dal.dao.CourseScheduleRecordDao">
     <select id="sumCourseTime" resultType="com.yonge.cooleshow.biz.dal.entity.CourseScheduleRecord">
         SELECT
-            teacherId,
-            courseId,
-            SUM( singleCourseTime ) AS consumTime,
-            COUNT( studentId ) AS studentCount,
-            endTime
-        FROM
-            (SELECT
-                 c.id_ AS courseId,
-                 c.teacher_id_ AS teacherId,
-                 p.user_id_ AS studentId,
-                 c.end_time_ AS endTime,
-                 c.single_course_time_ AS singleCourseTime
-             FROM course_schedule c
-             LEFT JOIN course_schedule_student_payment p ON c.id_ = p.course_id_
-             WHERE c.type_ = 'PIANO_ROOM_CLASS'
-             AND c.lock_ = 0
-             AND c.status_ IN ( 'ING', 'NOT_START' )
-             AND NOW() >= c.end_time_) a
-        GROUP BY courseId
+            c.id_ AS courseId,
+            c.teacher_id_ AS teacherId,
+            COUNT(1) AS studentCount,
+            c.end_time_ AS endTime,
+            c.single_course_time_ AS singleCourseTime
+        FROM course_schedule c
+        LEFT JOIN course_schedule_student_payment p ON c.id_ = p.course_id_
+        WHERE c.type_ = 'PIANO_ROOM_CLASS'
+        AND c.lock_ = 0
+        AND c.status_ IN ( 'ING', 'NOT_START' )
+        AND NOW() >= c.end_time_
+        GROUP BY c.id_
     </select>
     <select id="countTimeByTeacherId" resultType="java.lang.Long">
         SELECT SUM(consum_time_) FROM course_schedule_piano WHERE teacher_id_=#{teacherId} AND  date_format(end_time_,'%Y-%m') = #{month}

+ 1 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/CourseScheduleRepliedMapper.xml

@@ -137,6 +137,7 @@
         LEFT JOIN course_schedule s ON s.id_ = r.course_schedule_id_
         LEFT JOIN sys_user u ON u.id_ = r.student_id_
         WHERE r.course_group_type_ = 'PRACTICE'
+        AND r.student_replied_ != ""
         AND s.teacher_id_ = #{param.teacherId}
         <if test="param.studentName !=null and param.studentName !=''">
             AND u.username_ LIKE CONCAT('%', #{param.studentName}, '%')