|
@@ -1,22 +1,29 @@
|
|
|
package org.jeecg.modules.app.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import org.jeecg.modules.system.app.entity.AppBanner;
|
|
|
-import org.jeecg.modules.system.app.mapper.AppBannerMapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import org.jeecg.modules.app.dto.GetPlaceListDTO;
|
|
|
import org.jeecg.modules.app.service.IAppHomeService;
|
|
|
-import org.jeecg.modules.app.vo.AppBannerVO;
|
|
|
-import org.jeecg.modules.app.vo.CoureseVO;
|
|
|
-import org.jeecg.modules.app.vo.HomeVO;
|
|
|
+import org.jeecg.modules.app.vo.*;
|
|
|
+import org.jeecg.modules.system.app.entity.AppBanner;
|
|
|
import org.jeecg.modules.system.app.entity.AppCourese;
|
|
|
-import org.jeecg.modules.system.app.mapper.AppCoureseMapper;
|
|
|
-import org.jeecg.modules.system.app.mapper.AppCoursesPriceRulesMapper;
|
|
|
+import org.jeecg.modules.system.app.entity.AppInstructor;
|
|
|
+import org.jeecg.modules.system.app.mapper.*;
|
|
|
+import org.jeecg.modules.system.entity.SysDepart;
|
|
|
+import org.jeecg.modules.system.entity.SysUser;
|
|
|
+import org.jeecg.modules.system.mapper.SysDepartMapper;
|
|
|
+import org.jeecg.modules.system.mapper.SysUserMapper;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static org.jeecg.common.constant.CommonConstant.INSTRUCTOR;
|
|
|
+
|
|
|
@Service
|
|
|
public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
@Resource
|
|
@@ -24,37 +31,136 @@ public class AppHomeServiceImpl implements IAppHomeService {
|
|
|
@Resource
|
|
|
private AppCoureseMapper appCoureseMapper;
|
|
|
@Resource
|
|
|
- private AppCoursesPriceRulesMapper appCoursesPriceRulesMapper;
|
|
|
+ private AppInstructorMapper appInstructorMapper;
|
|
|
+ @Resource
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
+ @Resource
|
|
|
+ private SysDepartMapper sysDepartMapper;
|
|
|
+ @Resource
|
|
|
+ private AppSiteMapper appSiteMapper;
|
|
|
+ @Resource
|
|
|
+ private AppCategoryMapper appCategoryMapper;
|
|
|
+
|
|
|
@Override
|
|
|
- public HomeVO homeInfo(){
|
|
|
+ public HomeVO homeInfo() {
|
|
|
+ // 获取 banners
|
|
|
List<AppBanner> appBanners = appBannerMapper.selectList(Wrappers.<AppBanner>lambdaQuery()
|
|
|
- .eq(AppBanner::getDelFlag, 0));
|
|
|
- //精品课程
|
|
|
+ .eq(AppBanner::getDelFlag, 0).eq(AppBanner::getIsEnabled,1));
|
|
|
+
|
|
|
+ // 精品课程(最多3个)
|
|
|
List<AppCourese> appCoureseFine = appCoureseMapper.selectList(Wrappers.<AppCourese>lambdaQuery()
|
|
|
- .eq(AppCourese::getPriceType, 0).last("limit 3"));
|
|
|
- //免费课程
|
|
|
+ .eq(AppCourese::getPriceType, 0).last("LIMIT 3"));
|
|
|
+
|
|
|
+ // 免费课程(最多3个)
|
|
|
List<AppCourese> appCoureseFree = appCoureseMapper.selectList(Wrappers.<AppCourese>lambdaQuery()
|
|
|
- .eq(AppCourese::getPriceType, 1).last("limit 3"));
|
|
|
+ .eq(AppCourese::getPriceType, 1).last("LIMIT 3"));
|
|
|
+
|
|
|
+ // 合并课程信息
|
|
|
List<CoureseVO> courseVO = new ArrayList<>();
|
|
|
-// courseVO.addAll(convertToCoureseVOList(appCoureseFine));
|
|
|
-// courseVO.addAll(convertToCoureseVOList(appCoureseFree));
|
|
|
- return new HomeVO().setBannerList(appBanners.stream()
|
|
|
- .map(banner -> new AppBannerVO()
|
|
|
- .setId(banner.getId())
|
|
|
- .setEventType(banner.getEventType())
|
|
|
- .setEventValue(banner.getEventValue())
|
|
|
- .setSortOrder(banner.getSortOrder())
|
|
|
- .setImageUrl(banner.getImageUrl()))
|
|
|
- .collect(Collectors.toList()))
|
|
|
- .setCourseList(courseVO);
|
|
|
+ courseVO.addAll(convertToCoureseVOList(appCoureseFine));
|
|
|
+ courseVO.addAll(convertToCoureseVOList(appCoureseFree));
|
|
|
+
|
|
|
+ // 获取好评率最高的两个教练 ID
|
|
|
+ List<String> topInstructorUserIds = sysUserMapper.getUserIdListByRoleId(INSTRUCTOR).stream()
|
|
|
+ .map(userId -> {
|
|
|
+ AppInstructor instructor = appInstructorMapper.selectOne(
|
|
|
+ Wrappers.<AppInstructor>lambdaQuery().eq(AppInstructor::getUserId, userId));
|
|
|
+ return new Object() {
|
|
|
+ final String id = userId;
|
|
|
+ final Double goodRate = instructor != null ? Double.parseDouble(String.valueOf(instructor.getGoodRate())) : 0.0;
|
|
|
+ };
|
|
|
+ })
|
|
|
+ .sorted((a, b) -> Double.compare(b.goodRate, a.goodRate))
|
|
|
+ .limit(2)
|
|
|
+ .map(obj -> obj.id)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 构建教练列表
|
|
|
+ List<InstructorVO> instructorList = new ArrayList<>();
|
|
|
+ for (String userId : topInstructorUserIds) {
|
|
|
+ SysUser sysUser = sysUserMapper.selectById(userId);
|
|
|
+ AppInstructor appInstructor = appInstructorMapper.selectOne(
|
|
|
+ Wrappers.<AppInstructor>lambdaQuery().eq(AppInstructor::getUserId, userId));
|
|
|
+
|
|
|
+ InstructorVO instructorVO = new InstructorVO();
|
|
|
+ BeanUtils.copyProperties(instructorVO, appInstructor);
|
|
|
+
|
|
|
+ instructorVO.setId(sysUser.getId())
|
|
|
+ .setAvatar(sysUser.getAvatar())
|
|
|
+ .setName(sysUser.getRealname())
|
|
|
+ .setOrgName(sysDepartMapper.selectOne(Wrappers.<SysDepart>lambdaQuery()
|
|
|
+ .eq(SysDepart::getOrgCode, sysUser.getOrgCode())).getDepartName());
|
|
|
+
|
|
|
+ // 获取该教练的课程(最多取2个)
|
|
|
+ List<AppCourese> courses = appCoureseMapper.selectList(
|
|
|
+ Wrappers.<AppCourese>lambdaQuery().eq(AppCourese::getUserId, userId).last("LIMIT 2"));
|
|
|
+
|
|
|
+ List<InstructorVO.CourseInfoVO> courseInfoVOS = courses.stream()
|
|
|
+ .map(course -> {
|
|
|
+ InstructorVO.CourseInfoVO vo = new InstructorVO.CourseInfoVO();
|
|
|
+ BeanUtils.copyProperties(vo, course);
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ instructorVO.setCourseList(courseInfoVOS);
|
|
|
+ instructorList.add(instructorVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回首页数据
|
|
|
+ return new HomeVO()
|
|
|
+ .setBannerList(appBanners.stream()
|
|
|
+ .map(banner -> new AppBannerVO()
|
|
|
+ .setId(banner.getId())
|
|
|
+ .setEventType(banner.getEventType())
|
|
|
+ .setEventValue(banner.getEventValue())
|
|
|
+ .setSortOrder(banner.getSortOrder())
|
|
|
+ .setImageUrl(banner.getImageUrl()))
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .setCourseList(courseVO)
|
|
|
+ .setInstructorList(instructorList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author SheepHy
|
|
|
+ * @Description 合并课程信息
|
|
|
+ * @Date 9:14 2025/7/4
|
|
|
+ * @Param appCoureseList {@link List<AppCourese>}
|
|
|
+ * @return List<CoureseVO> {@link List<CoureseVO>}
|
|
|
+ **/
|
|
|
+ private List<CoureseVO> convertToCoureseVOList(List<AppCourese> appCoureseList) {
|
|
|
+ return appCoureseList.stream()
|
|
|
+ .map(courese -> new CoureseVO()
|
|
|
+ .setId(courese.getId()).setCover(courese.getCover())
|
|
|
+ .setPriceType(courese.getPriceType())
|
|
|
+ .setSellingPrice(courese.getSellingPrice()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
-// private List<CoureseVO> convertToCoureseVOList(List<AppCourese> appCoureseList) {
|
|
|
-// return appCoureseList.stream()
|
|
|
-// .map(courese -> new CoureseVO()
|
|
|
-// .setId(courese.getId()).setCover(courese.getCover())
|
|
|
-// .setPriceType(courese.getPriceType())
|
|
|
-// .setSellingPrice(appCoursesPriceRulesMapper.selectById(courese.getId()).get))
|
|
|
-// .collect(Collectors.toList());
|
|
|
-// }
|
|
|
+ @Override
|
|
|
+ public Page<PlaceVO> getPlaceList(GetPlaceListDTO getPlaceListDTO) {
|
|
|
+ Page<PlaceVO> page = new Page<>(getPlaceListDTO.getCurrent(), getPlaceListDTO.getSize());
|
|
|
+ Page<PlaceVO> placeList = appSiteMapper.getPlaceList(page, getPlaceListDTO.getVenueType());
|
|
|
+ placeList.getRecords().forEach(placeVO -> {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ String[] split = placeVO.getCategoryId().split(",");
|
|
|
+ Arrays.stream(split).forEach(id -> {
|
|
|
+ list.add(appCategoryMapper.selectById(id).getName());
|
|
|
+ });
|
|
|
+ //todo 待申请第三方地图接口
|
|
|
+ placeVO.setKm(0.0)
|
|
|
+ .setCategory(list);
|
|
|
+ });
|
|
|
+ if(getPlaceListDTO.getVenueType().equals("1")
|
|
|
+ || getPlaceListDTO.getVenueType().equals("2")
|
|
|
+ || getPlaceListDTO.getVenueType().equals("3")){
|
|
|
+ // 按 km 升序排序(从近到远)
|
|
|
+ placeList.getRecords().sort((p1, p2) -> {
|
|
|
+ Double km1 = p1.getKm();
|
|
|
+ Double km2 = p2.getKm();
|
|
|
+ return km1.compareTo(km2);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return placeList;
|
|
|
+ }
|
|
|
}
|