|
@@ -3,17 +3,20 @@ package org.jeecg.modules.app.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.jeecg.modules.app.service.IDetailService;
|
|
|
+import org.jeecg.modules.app.vo.CourseInfoVO;
|
|
|
import org.jeecg.modules.app.vo.PlaceInfoVO;
|
|
|
-import org.jeecg.modules.system.app.entity.AppInstructor;
|
|
|
-import org.jeecg.modules.system.app.entity.AppOrderProduct;
|
|
|
-import org.jeecg.modules.system.app.entity.AppSite;
|
|
|
-import org.jeecg.modules.system.app.entity.AppSitePriceRules;
|
|
|
+import org.jeecg.modules.system.app.entity.*;
|
|
|
import org.jeecg.modules.system.app.mapper.*;
|
|
|
+import org.jeecg.modules.system.util.PositionUtil;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
@Service
|
|
|
@Log4j2
|
|
@@ -23,6 +26,8 @@ public class DetailServiceImpl implements IDetailService {
|
|
|
@Resource
|
|
|
private AppCoursesPriceRulesMapper appCoursesPriceRulesMapper;
|
|
|
@Resource
|
|
|
+ private AppCoursesMapper appCoursesMapper;
|
|
|
+ @Resource
|
|
|
private AppOrderProductMapper appOrderProductMapper;
|
|
|
@Resource
|
|
|
private AppSitePriceRulesMapper appSitePriceRulesMapper;
|
|
@@ -58,6 +63,24 @@ public class DetailServiceImpl implements IDetailService {
|
|
|
return placeInfo;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CourseInfoVO getCourseInfo(String id, double latitude, double longitude) {
|
|
|
+ CourseInfoVO courseInfoVO = appCoursesMapper.getCourseInfo(id);
|
|
|
+ AppSite appSite = appSiteMapper.selectById(courseInfoVO.getSiteId());
|
|
|
+ courseInfoVO.setKm(PositionUtil.calculateDistance(latitude, longitude, appSite.getLatitude().doubleValue(), appSite.getLongitude().doubleValue()));
|
|
|
+ courseInfoVO.setSales(getCourseSales(id));
|
|
|
+ List<CourseInfoVO.CourseDetailVO> courseDetailVOList = new ArrayList<>();
|
|
|
+ appCoursesPriceRulesMapper.selectList(Wrappers.<AppCoursesPriceRules>lambdaQuery()
|
|
|
+ .eq(AppCoursesPriceRules::getCoursesId, courseInfoVO.getId())).forEach(appCourses -> {
|
|
|
+ CourseInfoVO.CourseDetailVO courseDetailVO = new CourseInfoVO.CourseDetailVO();
|
|
|
+ BeanUtils.copyProperties(courseDetailVO, appCourses);
|
|
|
+ courseDetailVOList.add(courseDetailVO);
|
|
|
+ });
|
|
|
+ courseInfoVO.setCourseDetail(courseDetailVOList);
|
|
|
+ //todo 评价查询待添加
|
|
|
+ return courseInfoVO;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return
|
|
|
* @Author SheepHy
|
|
@@ -76,4 +99,25 @@ public class DetailServiceImpl implements IDetailService {
|
|
|
}
|
|
|
return totalOrders;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @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)
|
|
|
+ .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
|
|
|
+ ));
|
|
|
+ }
|
|
|
}
|