This commit is contained in:
wangjinlei
2024-05-09 17:42:31 +08:00
parent 7d8f0d85b3
commit 14c70bb6c5
5 changed files with 74 additions and 14 deletions

View File

@@ -2,8 +2,16 @@ package com.peanut.modules.common.dao;
import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.CourseCatalogueEntity;
import com.peanut.modules.common.vo.CourseCatalogueVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface CourseCatalogueDao extends MPJBaseMapper<CourseCatalogueEntity> {
List<CourseCatalogueVo> getCanBindProductAndCourse(@Param("ids")List<Integer> ids, @Param("keywords")String keywords,@Param("page")Integer page,@Param("limit")Integer limit);
Integer getCanBindProductAndCourseCount(@Param("ids")List<Integer> ids, @Param("keywords")String keywords);
}

View File

@@ -178,7 +178,7 @@ public class ShopProductController {
@RequestMapping("/getCanBindProductAndCourse")
public R getCanBindProductAndCourse(@RequestBody ParamTo param){
Page<CourseCatalogueVo> canBindProductAndCourse = shopProductService.getCanBindProductAndCourse(param);
Map<String, Object> canBindProductAndCourse = shopProductService.getCanBindProductAndCourse(param);
return R.ok().put("page",canBindProductAndCourse);
}

View File

@@ -54,5 +54,5 @@ public interface ShopProductService extends IService<ShopProduct> {
List<CourseCatalogueVo> getHasBindProductAndCourse(int productId);
Page<CourseCatalogueVo> getCanBindProductAndCourse(ParamTo param);
Map<String, Object> getCanBindProductAndCourse(ParamTo param);
}

View File

@@ -1,11 +1,13 @@
package com.peanut.modules.master.service.impl;
import cn.hutool.core.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
@@ -16,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -238,19 +241,18 @@ public class ShopProductServiceImpl extends ServiceImpl<ShopProductDao, ShopProd
}
@Override
public Page<CourseCatalogueVo> getCanBindProductAndCourse(ParamTo param) {
public Map<String, Object> getCanBindProductAndCourse(ParamTo param) {
List<Integer> catalogueIds = shopProductCourseDao.selectList(new LambdaQueryWrapper<ShopProductCourseEntity>().eq(ShopProductCourseEntity::getProductId, param.getId())).stream().map(ShopProductCourseEntity::getCatalogueId).collect(Collectors.toList());
MPJLambdaWrapper<CourseCatalogueEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseCatalogueEntity::getCourseId);
wrapper.notIn(catalogueIds.size()>0,CourseCatalogueEntity::getId,catalogueIds);
wrapper.like(StringUtils.isNotBlank(param.getKeywords()),CourseEntity::getTitle,param.getKeywords());
wrapper.selectAs(CourseEntity::getTitle,"courseTitle");
wrapper.selectAs(CourseCatalogueEntity::getTitle,"CourseCatalogueTitle");
wrapper.select(CourseEntity::getImage);
wrapper.selectAs(CourseEntity::getId,"courseId");
wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId");
Page<CourseCatalogueVo> courseCatalogueVoPage = courseCatalogueDao.selectJoinPage(new Page<>(param.getPage(), param.getLimit()), CourseCatalogueVo.class, wrapper);
return courseCatalogueVoPage;
int page = param.getPage();
int limit = param.getLimit();
Integer canBindProductAndCourseCount = courseCatalogueDao.getCanBindProductAndCourseCount(catalogueIds, param.getKeywords());
List<CourseCatalogueVo> canBindProductAndCourse = courseCatalogueDao.getCanBindProductAndCourse(catalogueIds, param.getKeywords(), (page-1)*limit, param.getLimit());
Map<String, Object> flag = new HashMap<>();
flag.put("count",canBindProductAndCourseCount);
flag.put("data",canBindProductAndCourse);
flag.put("page",page);
flag.put("limit",limit);
return flag;
}
@Override

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.peanut.modules.common.dao.CourseCatalogueDao">
<select id="getCanBindProductAndCourse" resultType="com.peanut.modules.common.vo.CourseCatalogueVo">
select
t1.id as courseId,
t2.id as courseCatalogueId,
t1.title as courseTitle,
t2.title as CourseCatalogueTitle,
t2.image
from course_catalogue t1
left join course t2 on t1.course_id = t2.id
where
t1.del_flag = 0
and t2.del_flag = 0
<if test="keywords !=null and keywords != ''">
and t2.title like concat('%', #{keywords} , '%')
</if>
<if test="ids.size() > 0">
and t1.id not in
<foreach collection="ids" item="menu_id" separator="," open="(" close=")">
#{menu_id}
</foreach>
</if>
limit #{page},#{limit}
</select>
<select id="getCanBindProductAndCourseCount" resultType="java.lang.Integer">
select
count(*)
from course_catalogue t1
left join course t2 on t1.course_id = t2.id
where
t1.del_flag = 0
and t2.del_flag = 0
<if test="keywords !=null and keywords != ''">
and t2.title like concat('%', #{keywords} , '%')
</if>
<if test="ids.size() > 0">
and t1.id not in
<foreach collection="ids" item="menu_id" separator="," open="(" close=")">
#{menu_id}
</foreach>
</if>
</select>
</mapper>