|
@@ -2,18 +2,23 @@ package org.jeecg.modules.app.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
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,16 +28,25 @@ public class DetailServiceImpl implements IDetailService {
|
|
|
@Resource
|
|
|
private AppCoursesPriceRulesMapper appCoursesPriceRulesMapper;
|
|
|
@Resource
|
|
|
+ private AppCoursesMapper appCoursesMapper;
|
|
|
+ @Resource
|
|
|
private AppOrderProductMapper appOrderProductMapper;
|
|
|
@Resource
|
|
|
private AppSitePriceRulesMapper appSitePriceRulesMapper;
|
|
|
@Resource
|
|
|
private AppInstructorMapper appInstructorMapper;
|
|
|
+ @Resource
|
|
|
+ private AppOrderMapper appOrderMapper;
|
|
|
|
|
|
@Override
|
|
|
public PlaceInfoVO getPlaceInfo(String id) {
|
|
|
+ LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
AppSite appSite = appSiteMapper.selectById(id);
|
|
|
PlaceInfoVO placeInfo = appSiteMapper.getPlaceInfo(id);
|
|
|
+ AppSitePriceRules appSitePriceRules = appSitePriceRulesMapper.selectOne(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
+ .eq(AppSitePriceRules::getSiteId, id)
|
|
|
+ .eq(AppSitePriceRules::getStatus, 0)
|
|
|
+ .last("limit 1"));
|
|
|
List<PlaceInfoVO.InstructorVO> instructorVOList = new ArrayList<>();
|
|
|
List<AppInstructor> appInstructors = appInstructorMapper.selectList(Wrappers.<AppInstructor>lambdaQuery()
|
|
|
.eq(AppInstructor::getOrgCode, appSite.getOrgCode()));
|
|
@@ -43,19 +57,60 @@ public class DetailServiceImpl implements IDetailService {
|
|
|
instructorVOList.add(vo);
|
|
|
}
|
|
|
}
|
|
|
- AppSitePriceRules appSitePriceRules = appSitePriceRulesMapper.selectOne(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
- .eq(AppSitePriceRules::getSiteId, id)
|
|
|
- .eq(AppSitePriceRules::getStatus, 0)
|
|
|
- .last("limit 1"));
|
|
|
- PlaceInfoVO.PlaceInfoMsgVO placeInfoMsgVO = new PlaceInfoVO.PlaceInfoMsgVO();
|
|
|
- placeInfoMsgVO.setName(appSite.getName())
|
|
|
- .setSales(getPlaceSales(id))
|
|
|
- .setOriginalPrice(appSitePriceRules.getOriginalPrice())
|
|
|
- .setSellingPrice(appSitePriceRules.getSellingPrice());
|
|
|
- placeInfo.setInstructorVOList(instructorVOList)
|
|
|
- .setPlaceInfoMsgVO(placeInfoMsgVO);
|
|
|
+ List<PlaceInfoVO.CourseInfoVO> courseInfoVOList = new ArrayList<>();
|
|
|
+ appCoursesMapper.selectList(Wrappers.<AppCourses>lambdaQuery()
|
|
|
+ .eq(AppCourses::getSiteId, id)
|
|
|
+ .eq(AppCourses::getStatus, 0)
|
|
|
+ .eq(AppCourses::getDelFlag, 0)).forEach(appCourses -> {
|
|
|
+ PlaceInfoVO.CourseInfoVO courseInfoVO = new PlaceInfoVO.CourseInfoVO();
|
|
|
+ BeanUtils.copyProperties(courseInfoVO, appCourses);
|
|
|
+ courseInfoVO.setSales(getCourseSalesCount(appCourses.getId()));
|
|
|
+ courseInfoVO.setSalesYear(getCourseSales(appCourses.getId()));
|
|
|
+ courseInfoVO.setPriceType(isFirstPurchase(user.getId()));
|
|
|
+ courseInfoVOList.add(courseInfoVO);
|
|
|
+ });
|
|
|
+ placeInfo.setInstructorVOList(instructorVOList);
|
|
|
+ placeInfo.setCourseInfoVOList(courseInfoVOList);
|
|
|
+ if(appSite.getType() == 0){
|
|
|
+ //todo 评价查询待添加
|
|
|
+ PlaceInfoVO.PlaceInfoMsgVO placeInfoMsgVO = new PlaceInfoVO.PlaceInfoMsgVO();
|
|
|
+ placeInfoMsgVO.setName(appSite.getName())
|
|
|
+ .setSales(getPlaceSales(id))
|
|
|
+ .setOriginalPrice(appSitePriceRules.getOriginalPrice())
|
|
|
+ .setSellingPrice(appSitePriceRules.getSellingPrice());
|
|
|
+ placeInfo.setPlaceInfoMsgVO(placeInfoMsgVO);
|
|
|
+ return placeInfo;
|
|
|
+ }else if(appSite.getType() == 1){
|
|
|
+// //todo 评价查询待添加
|
|
|
+ PlaceInfoVO.PlaceInfoMsgVO placeInfoMsgVO = new PlaceInfoVO.PlaceInfoMsgVO();
|
|
|
+ placeInfoMsgVO.setName(appSite.getName())
|
|
|
+ .setSales(getPlaceSales(id))
|
|
|
+ .setOriginalPrice(appSitePriceRules.getOriginalPrice())
|
|
|
+ .setSellingPrice(appSitePriceRules.getSellingPrice());
|
|
|
+ placeInfo.setPlaceInfoMsgVO(placeInfoMsgVO);
|
|
|
+ return placeInfo;
|
|
|
+ }else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @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 placeInfo;
|
|
|
+ return courseInfoVO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -65,7 +120,7 @@ public class DetailServiceImpl implements IDetailService {
|
|
|
* @Date 20:02 2025/7/7
|
|
|
* @Param
|
|
|
**/
|
|
|
- public int getPlaceSales(String id) {
|
|
|
+ private int getPlaceSales(String id) {
|
|
|
List<String> ids = appCoursesPriceRulesMapper.selectRuleIdsByCourseId(id);
|
|
|
int totalOrders = 0;
|
|
|
if (!ids.isEmpty()) {
|
|
@@ -76,4 +131,55 @@ 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
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @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;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|