Bläddra i källkod

Merge branch 'zx_saas_task_0310' of http://git.dayaedu.com/yonge/mec into dev

zouxuan 3 månader sedan
förälder
incheckning
72d40e7eee

+ 8 - 0
mec-application/src/main/java/com/ym/mec/web/controller/TaskController.java

@@ -774,4 +774,12 @@ public class TaskController extends BaseController {
     public void deleteOverdueHomework(){
         studentCourseHomeworkService.deleteOverdueHomework();
     }
+
+    /**
+     * 平衡关系定时任务
+     */
+    @GetMapping("/balanceRelation")
+	public void balanceRelation(){
+		studentService.balanceRelation();
+	}
 }

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentDao.java

@@ -403,4 +403,8 @@ public interface StudentDao extends com.ym.mec.common.dal.BaseDAO<Integer, Stude
     List<Integer> queryByCoopIds(@Param("coopId") Integer coopId);
 
     void updateCloudTeacherEndTime(@Param("studentId") Integer studentId);
+
+    void balanceRelation(@Param("lastDayOfLastMonth") String lastDayOfLastMonth,
+                         @Param("firstDayOfThisMonth") String firstDayOfThisMonth,
+                         @Param("firstDayOfLastMonth") String firstDayOfLastMonth);
 }

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

@@ -248,4 +248,9 @@ public interface StudentService extends BaseService<Integer, Student> {
     PageInfo<Student> queryBaseInfoByPage(QueryInfo queryInfo);
 
     Map<Integer,SysUser> getUserMapByIds(List<Integer> userIds);
+
+    /**
+     * 平衡关系定时任务
+     */
+    void balanceRelation();
 }

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

@@ -1151,11 +1151,11 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                 PaymentClose close = paymentService.close(order.getTransNo(), "超时未支付关闭", order.getOrderNo());
                 if (close == null) {
                     log.error("订单关闭失败,orderNo:{}", order.getOrderNo());
-                    throw new BizException("订单关闭失败,稍后请重试");
+                    throw new BizException("上一笔订单关闭失败,稍后请重试");
                 }
                 if (close.getStatus() != PaymentStatus.SUCCESSED) {
                     log.error("关闭订单失败,orderNo:{},msg:{}", order.getOrderNo(), close.getMsg());
-                    throw new BizException("关闭订单失败,稍后请重试");
+                    throw new BizException("上一笔订单关闭失败,稍后请重试");
                 }
             } else {
                 return BaseController.failed("该订单已关闭,请重新购买!");

+ 14 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentServiceImpl.java

@@ -67,8 +67,6 @@ public class StudentServiceImpl extends BaseServiceImpl<Integer, Student> implem
     @Autowired
     private MemberRankSettingService memberRankSettingService;
     @Autowired
-    private SysConfigDao sysConfigDao;
-    @Autowired
     private SysTenantConfigService sysTenantConfigService;
     @Autowired
     private SysMessageService sysMessageService;
@@ -1671,6 +1669,20 @@ public class StudentServiceImpl extends BaseServiceImpl<Integer, Student> implem
         return sysUsers.stream().collect(Collectors.toMap(SysUser::getId, Function.identity()));
     }
 
+    @Override
+    public void balanceRelation() {
+        Date now = new Date();
+        //获取上个月最后一天
+        String lastDayOfLastMonth = DateUtil.format(DateUtil.getLastDayOfMonth(DateUtil.addMonths(now, -1)), DateUtil.ISO_EXPANDED_DATE_FORMAT);
+        //获取上个月第一天
+        String firstDayOfLastMonth = DateUtil.format(DateUtil.getFirstDayOfMonth(DateUtil.addMonths(now, -1)), DateUtil.ISO_EXPANDED_DATE_FORMAT);
+        //获取当月第一天
+        String firstDayOfThisMonth = DateUtil.format(DateUtil.getFirstDayOfMonth(now), DateUtil.ISO_EXPANDED_DATE_FORMAT);
+        //汇总平衡关系
+        studentDao.balanceRelation(lastDayOfLastMonth, firstDayOfThisMonth,firstDayOfLastMonth);
+
+    }
+
     private int queryBaseInfoCount(Map<String, Object> params) {
         return studentDao.queryBaseInfoCount(params);
     }

+ 46 - 33
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentStatisticsServiceImpl.java

@@ -17,6 +17,8 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.redisson.api.RAtomicLong;
+import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
@@ -34,7 +36,7 @@ public class StudentStatisticsServiceImpl extends BaseServiceImpl<Integer, Stude
 	@Autowired
 	private StudentBasicInfoDao studentBasicInfoDao;
 	@Autowired
-	private RedisCache<String,Integer> redisCache;
+	private RedissonClient redissonClient;
 
 	@Override
 	public BaseDAO<Integer, StudentStatistics> getDAO() {
@@ -48,54 +50,65 @@ public class StudentStatisticsServiceImpl extends BaseServiceImpl<Integer, Stude
 
     @Override
 	public void updateStudentStatistics() {
-		//更新学员基本信息
+		// 更新学员基本信息
 		studentBasicInfoDao.updateStudentBasicInfo();
-		RedisTemplate<String, Integer> redisTemplate = redisCache.getRedisTemplate();
-		Integer num = redisTemplate.opsForValue().get("updateStudentStatisticsNum:");
-		if(num == null || num == 1){
-			if(num == null){
-				num = 1;
-			}
-			//更新未排课总数
+
+		// 获取 Redis 中的 AtomicLong 对象,表示统计数字
+		RAtomicLong atomicLong = redissonClient.getAtomicLong("updateStudentStatisticsNum:");
+
+		// 获取当前计数值
+		long num = atomicLong.get();
+
+		if (num == 0) {
+			// 设置初始值为 1 如果 num 为空
+			atomicLong.set(1);
+			num = 1; // 初始值为 1
+		}
+
+		// 根据 num 的值更新学员统计数据
+		if (num == 1) {
+			// 更新未排课总数
 			studentStatisticsDao.updateNoCourseNum();
-		}else if (num == 2){
-			//更新未开始价值总和
+		} else if (num == 2) {
+			// 更新未开始价值总和
 			studentStatisticsDao.updateNotStartCourseFee();
-		}else if (num == 3){
-			//更新未排课价值
+		} else if (num == 3) {
+			// 更新未排课价值
 			studentStatisticsDao.updateNoCourseFee();
-		}else if (num == 4){
-			//更新第一次课的时间\最近一次课时间
+		} else if (num == 4) {
+			// 更新第一次课的时间、最近一次课时间
 			studentStatisticsDao.updateFirstAndLastCourseTime();
-		}else if (num == 5){
-			//更新进行中课程组数量
+		} else if (num == 5) {
+			// 更新进行中课程组数量
 			studentStatisticsDao.updateNormalGroupNum();
-		}else if (num == 6){
-			//更新总课时数、已完成、剩余课时数、最近30天课耗、最近1年课耗
+		} else if (num == 6) {
+			// 更新总课时数、已完成、剩余课时数、最近30天课耗、最近1年课耗
 			studentStatisticsDao.updateCourseNum();
-		}else if (num == 7){
-			//更新声部班老师
+		} else if (num == 7) {
+			// 更新声部班老师
 			studentBasicInfoDao.updateSubjectTeacher();
-		}else if (num == 8){
-			//更新乐团主管、指导老师
+		} else if (num == 8) {
+			// 更新乐团主管、指导老师
 			studentStatisticsDao.updateTeacherAndEdu();
-		}else if (num == 8){
-			//更新学员合作单位
-			studentStatisticsDao.updateCooperationOrgan();
 		} else if (num == 9) {
-			//更新第一次付费时间
+			// 更新学员合作单位
+			studentStatisticsDao.updateCooperationOrgan();
+		} else if (num == 10) {
+			// 更新第一次付费时间
 			studentStatisticsDao.updateFirstOrderTime();
-			num = 0;
+			// 重置 num 为 0 完成所有更新
+			atomicLong.set(0);
 		}
-		num++;
-		redisTemplate.opsForValue().set("updateStudentStatisticsNum:",num);
+
+		// 递增 num 的值,进入下一个步骤
+		atomicLong.incrementAndGet();
 	}
 
 	public int countStatistics(StudentStatisticsQueryInfo queryInfo){
 		Map<String, Object> params = new HashMap<String, Object>();
 		MapUtil.populateMap(params, queryInfo);
 		if(StringUtils.isNotEmpty(queryInfo.getOrganId())){
-			List<Integer> organIdList = Arrays.stream(queryInfo.getOrganId().split(",")).map(id -> Integer.valueOf(id)).collect(Collectors.toList());
+			List<Integer> organIdList = Arrays.stream(queryInfo.getOrganId().split(",")).map(Integer::valueOf).collect(Collectors.toList());
 			params.put("organIdList",organIdList);
 		}
 		return studentStatisticsDao.countStatistics(params);
@@ -128,7 +141,7 @@ public class StudentStatisticsServiceImpl extends BaseServiceImpl<Integer, Stude
     public StudentStatisticsSumDto studentSmallClassStatisticsSum(String groupType,String organId) {
 		List<Integer> organIdList = new ArrayList<>();
 		if(StringUtils.isNotEmpty(organId)){
-			organIdList = Arrays.stream(organId.split(",")).map(id -> Integer.valueOf(id)).collect(Collectors.toList());
+			organIdList = Arrays.stream(organId.split(",")).map(Integer::valueOf).collect(Collectors.toList());
 		}
 		StudentStatisticsSumDto dto = studentStatisticsDao.studentSmallClassStatisticsSum(groupType, organIdList);
 		//获取进行中的学员数量
@@ -144,7 +157,7 @@ public class StudentStatisticsServiceImpl extends BaseServiceImpl<Integer, Stude
 		StudentStatisticsSumForDateDto sumForDateDto = new StudentStatisticsSumForDateDto();
 		List<Integer> organIdList = new ArrayList<>();
 		if(StringUtils.isNotEmpty(organId)){
-			organIdList = Arrays.stream(organId.split(",")).map(id -> Integer.valueOf(id)).collect(Collectors.toList());
+			organIdList = Arrays.stream(organId.split(",")).map(Integer::valueOf).collect(Collectors.toList());
 		}
 		//获取流失人数
 //		sumForDateDto.setLostNum(studentStatisticsDao.countLostStudentNum(groupType,startDate,endDate,organIdList));

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectServiceImpl.java

@@ -315,7 +315,8 @@ public class SubjectServiceImpl extends BaseServiceImpl<Integer, Subject> implem
         List<StudentSubjectDto> subjects = subjectDao.getSubjectByStudentId(studentIds);
         Map<Integer, StudentSubjectDto> map = new HashMap<>();
         if (!CollectionUtils.isEmpty(subjects)) {
-            map = subjects.stream().collect(Collectors.toMap(StudentSubjectDto::getStudentId, Function.identity()));
+            map = subjects.stream().filter(o->o.getSubjectId() !=null)
+                    .collect(Collectors.toMap(StudentSubjectDto::getStudentId, Function.identity()));
         }
         return map;
     }

+ 8 - 0
mec-biz/src/main/resources/config/mybatis/StudentMapper.xml

@@ -1559,4 +1559,12 @@
         and mg.status_ = 'PROGRESS'
         and mg.cooperation_organ_id_ = #{coopId}
     </select>
+    <select id="balanceRelation">
+        select firstMonthVipReportStatis(#{firstDayOfThisMonth});
+        select firstMonthMusicClassReportStatis(#{firstDayOfThisMonth});
+        select currentMonthVipReportStatis(#{firstDayOfLastMonth},#{lastDayOfLastMonth});
+        select currentMonthMusicClassReportStatis(#{firstDayOfLastMonth},#{lastDayOfLastMonth});
+        select lastMonthVipReportStatis(#{lastDayOfLastMonth});
+        select lastMonthMusicClassReportStatis('#{lastDayOfLastMonth});
+    </select>
 </mapper>

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

@@ -8,6 +8,6 @@
         a.train_time_ = a.train_time_ + #{playTime}
         where a.user_id_ = #{userId}
         and a.camp_id_ = #{campId}
-        and a.day_ = date_format(now(), '%Y-%m-%d')
+        and a.day_ = CURDATE()
     </update>
 </mapper>

+ 3 - 0
mec-client-api/src/main/java/com/ym/mec/task/TaskRemoteService.java

@@ -335,4 +335,7 @@ public interface TaskRemoteService {
     @GetMapping("/task/deleteOverdueHomework")
     void deleteOverdueHomework();
 
+    @GetMapping("task/balanceRelation")
+    void balanceRelation();
+
 }

+ 5 - 1
mec-client-api/src/main/java/com/ym/mec/task/fallback/TaskRemoteServiceFallback.java

@@ -1,6 +1,5 @@
 package com.ym.mec.task.fallback;
 
-import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.task.TaskRemoteService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -385,4 +384,9 @@ public class TaskRemoteServiceFallback implements TaskRemoteService {
     public void deleteOverdueHomework() {
         logger.error("删除过期作业失败");
     }
+
+    @Override
+    public void balanceRelation() {
+        logger.error("平衡关系更新失败");
+    }
 }

+ 21 - 0
mec-task/src/main/java/com/ym/mec/task/jobs/BalanceRelationTask.java

@@ -0,0 +1,21 @@
+package com.ym.mec.task.jobs;
+
+import com.ym.mec.task.TaskRemoteService;
+import com.ym.mec.task.core.BaseTask;
+import com.ym.mec.task.core.TaskException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class BalanceRelationTask extends BaseTask {
+
+    @Autowired
+    private TaskRemoteService taskRemoteService;
+
+    @Override
+    public void execute() throws TaskException {
+        taskRemoteService.balanceRelation();
+    }
+
+}
+