|
@@ -0,0 +1,178 @@
|
|
|
+package org.jeecg.modules.app.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.modules.app.service.ICoachService;
|
|
|
+import org.jeecg.modules.app.vo.coach.AppCoachDetailsRequestVO;
|
|
|
+import org.jeecg.modules.app.vo.coach.AppCoachDetailsVO;
|
|
|
+import org.jeecg.modules.app.vo.coach.AppCoachVO;
|
|
|
+import org.jeecg.modules.app.vo.course.CourseRequestVo;
|
|
|
+import org.jeecg.modules.app.vo.course.CourseResponseVo;
|
|
|
+import org.jeecg.modules.system.app.entity.AppCategory;
|
|
|
+import org.jeecg.modules.system.app.entity.AppOrder;
|
|
|
+import org.jeecg.modules.system.app.entity.AppOrderProduct;
|
|
|
+import org.jeecg.modules.system.app.mapper.*;
|
|
|
+import org.jeecg.modules.system.util.PositionUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Log4j2
|
|
|
+public class CoachServiceImpl implements ICoachService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AppInstructorMapper appInstructorMapper;
|
|
|
+ @Autowired
|
|
|
+ AppCategoryMapper appCategoryMapper;
|
|
|
+ @Autowired
|
|
|
+ AppCoursesMapper appCoursesMapper;
|
|
|
+ @Autowired
|
|
|
+ private AppOrderMapper appOrderMapper;
|
|
|
+ @Autowired
|
|
|
+ private AppOrderProductMapper appOrderProductMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<List<AppCoachVO>> findCoachList() {
|
|
|
+ List<AppCoachVO> appCoachVOList= appInstructorMapper.findCoachList();
|
|
|
+ List<AppCategory> appCategories = appCategoryMapper.selectList(Wrappers.<AppCategory>lambdaQuery().eq(AppCategory::getDelFlag, 0));
|
|
|
+ for (AppCoachVO appCoachVO : appCoachVOList) {
|
|
|
+ String trainingProgramsName=getTrainingProgramsName(appCoachVO.getTrainingPrograms(),appCategories);
|
|
|
+ appCoachVO.setTrainingProgramsName(trainingProgramsName);
|
|
|
+ }
|
|
|
+ return Result.ok(appCoachVOList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<AppCoachDetailsVO> findByCoachId(AppCoachDetailsRequestVO appCoachDetailsRequestVO, String userId) {
|
|
|
+ AppCoachDetailsVO appCoachDetailsVO = appInstructorMapper.findById(appCoachDetailsRequestVO.getId());
|
|
|
+ List<AppCategory> appCategories = appCategoryMapper.selectList(Wrappers.<AppCategory>lambdaQuery().eq(AppCategory::getDelFlag, 0));
|
|
|
+ String trainingProgramsName=getTrainingProgramsName(appCoachDetailsVO.getTrainingPrograms(),appCategories);
|
|
|
+ appCoachDetailsVO.setTrainingProgramsName(trainingProgramsName);
|
|
|
+ List<String> honorList = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotEmpty(appCoachDetailsVO.getHonor())&&appCoachDetailsVO.getHonor().indexOf(",")>0){
|
|
|
+ honorList = Arrays.asList(appCoachDetailsVO.getHonor().split(","));
|
|
|
+ }else {
|
|
|
+ honorList.add(appCoachDetailsVO.getHonor());
|
|
|
+ }
|
|
|
+ appCoachDetailsVO.setHonorImgList(honorList);
|
|
|
+ CourseRequestVo courseRequestVo = new CourseRequestVo();
|
|
|
+ courseRequestVo.setInstructorId(appCoachDetailsRequestVO.getId());
|
|
|
+ //写死默认一页50条 全部展示
|
|
|
+ Page<CourseResponseVo> page = new Page<CourseResponseVo>(1,100);
|
|
|
+ //查询课时列表
|
|
|
+ IPage<CourseResponseVo> byCourseList = appCoursesMapper.findByCourseList(page, courseRequestVo);
|
|
|
+ appCoachDetailsVO.setCourseInfoVOList(byCourseList.getRecords());
|
|
|
+ if (appCoachDetailsVO.getCourseInfoVOList()!=null){
|
|
|
+ for (CourseResponseVo courseResponseVo : appCoachDetailsVO.getCourseInfoVOList()) {
|
|
|
+ int courseSales = getCourseSales(courseResponseVo.getId());
|
|
|
+ courseResponseVo.setAnnualSalesNum(courseSales);
|
|
|
+ int courseSalesCount = getCourseSalesCount(courseResponseVo.getId());
|
|
|
+ courseResponseVo.setSaleNum(courseSalesCount);
|
|
|
+ int firstPurchase = isFirstPurchase(userId);
|
|
|
+ courseResponseVo.setIsOneBuy(firstPurchase);
|
|
|
+ double km = PositionUtil.calculateDistance(appCoachDetailsRequestVO.getLatitude(), appCoachDetailsRequestVO.getLongitude(), courseResponseVo.getLatitude().doubleValue(), courseResponseVo.getLongitude().doubleValue());
|
|
|
+ courseResponseVo.setKm(km);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //缺少授课人数和订单数,评价
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return Result.ok(appCoachDetailsVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author SheepHy
|
|
|
+ * @Description 计算当前课程年销售数
|
|
|
+ * @Date 15:47 2025/7/8
|
|
|
+ * @Param id 课程id
|
|
|
+ * @return int 课程年销售数
|
|
|
+ **/
|
|
|
+ private int getCourseSales(String id) {
|
|
|
+ // 获取当前年份的时间范围(如:2025-01-01 00:00:00 到 2026-01-01 00:00:00)
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ LocalDateTime startOfYear = now.withDayOfYear(1).atStartOfDay(); // 当前年份第一天
|
|
|
+ LocalDateTime endOfYear = startOfYear.plusYears(1); // 下一年第一天
|
|
|
+
|
|
|
+ return Math.toIntExact(appOrderProductMapper.selectCount(
|
|
|
+ Wrappers.<AppOrderProduct>lambdaQuery()
|
|
|
+ .eq(AppOrderProduct::getProductId, id)
|
|
|
+ .eq(AppOrderProduct::getStatus,0)
|
|
|
+ .eq(AppOrderProduct::getDelFlag,0)
|
|
|
+ .eq(AppOrderProduct::getProductOrderStatus,1)
|
|
|
+ .ge(AppOrderProduct::getCreateTime, Date.from(startOfYear.atZone(ZoneId.systemDefault()).toInstant())) // >= 2025-01-01
|
|
|
+ .lt(AppOrderProduct::getCreateTime, Date.from(endOfYear.atZone(ZoneId.systemDefault()).toInstant())) // < 2026-01-01
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author SheepHy
|
|
|
+ * @Description 计算当前课程销售数
|
|
|
+ * @Date 15:47 2025/7/8
|
|
|
+ * @Param id 课程id
|
|
|
+ * @return int 课程年销售数
|
|
|
+ **/
|
|
|
+ private int getCourseSalesCount(String id) {
|
|
|
+ return Math.toIntExact(appOrderProductMapper.selectCount(
|
|
|
+ Wrappers.<AppOrderProduct>lambdaQuery()
|
|
|
+ .eq(AppOrderProduct::getProductId, id)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author SheepHy
|
|
|
+ * @Description 查询用户是否为第一次购买
|
|
|
+ * @Date 16:54 2025/7/8
|
|
|
+ * @Param
|
|
|
+ * @return
|
|
|
+ **/
|
|
|
+ private int isFirstPurchase(String userId) {
|
|
|
+ AppOrder appOrder = appOrderMapper.selectOne(Wrappers.<AppOrder>lambdaQuery()
|
|
|
+ .eq(AppOrder::getUpdateBy, userId).last("limit 1"));
|
|
|
+ if(null == appOrder){
|
|
|
+ return 1;
|
|
|
+ }else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private String getTrainingProgramsName(String trainingPrograms,List<AppCategory> appCategories){
|
|
|
+ String trainingProgramsName ="";
|
|
|
+ if (StringUtils.isNotEmpty(trainingPrograms)&&trainingPrograms.indexOf(",")>0){
|
|
|
+ String[] split = trainingPrograms.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ for (AppCategory appCategory : appCategories) {
|
|
|
+ if (appCategory.getId().equals(s)){
|
|
|
+ if (StringUtils.isNotEmpty(trainingProgramsName)){
|
|
|
+ trainingProgramsName=trainingProgramsName+"、"+appCategory.getName();
|
|
|
+ }else{
|
|
|
+ trainingProgramsName=appCategory.getName();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ for (AppCategory appCategory : appCategories) {
|
|
|
+ if (appCategory.getId().equals(trainingPrograms)){
|
|
|
+ trainingProgramsName=appCategory.getName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return trainingProgramsName;
|
|
|
+ }
|
|
|
+}
|